Thursday, April 11, 2013

Read SAS data into R (SAS is required)

Those 3 ways can read SAS data into R. I prefer the first method since it gives the most choice to control.

### To read SAS data into R(SAS is necessary)
##1: first use SAS to export data to csv or dlm, then use R
libname test "/data/temp/hsong/test";
proc export data=test.hsb12 outfile="/data/temp/hsong/test/sasxport" dbms=dlm replace;
# Then read in the exported data with R
read.table("/data/temp/hsong/test/sasxport", header=T)
##2: to read in with the package {Hmisc}
hsb12=sas.get(lib="/data/temp/hsong/test", mem="hsb12",
##3: read with library {foreign}, but I did not run it successfully

1 comment: