How to import SAS data set into R

at 07 November 2007

The import of data into R is still a bit complicated if the original data are stored in the SAS-data format. Though solutions have existed for a long time, see e.g. the R-documentation concerning Importing from other statistical systems, it is complicated to use these facilities. They are based on functions which need to call the SAS-program from R. The settings for doing this do not always correspond to the settings on the computers we use.

I have written a short note/web-page with focus on the export problem from the SAS point of view. The note compares three different intermediate formats: csv, xls and xport format.

In normal use, the route via the xls format seems best. Data are exported via SAS code similar to:

 
libname sasdata "C:/SASImport";
libname out Excel
"C:/SASImport/file798b12e1.xls";
data out.rimporttest;
set sasdata.rimporttest;
run;

and imported into R via the read.xls command in the xlsReadWrite package.


Further detail in the note, which also includes R-functions. The note is also available as a pdf-file

1 comments:

Anonymous said...

Please correct your html presentation of the code of the script

sasprog <-ťcat(libnamestr,outlibnamestr,datastepstr, sep="\n",file=sasprogname)

which is annoying when copying the script part.