1 min read

Import .Rdata to SAS, along with Labels

I didn’t play with SAS/IML for a while. I call it back when I need to read some R format data.

Technically, .Rdata is not a data format. It’s rather a big container to hold bunch of R objects:

Rdata

In this example, when a .Rdata is loaded, 3 objects are included where ‘data’(the ‘real’ data) and ‘desc’ (data description portion) are of our interests.

SAS/IML offers a nice interface to call R command which can be used to read the R format data:

proc iml;
submit / R;
load(“C:/data/w5/R data sets for 5e/GPA1.RData”)
endsubmit;

    call ImportDataSetFromR(“work.GPA1”, “data“);
call ImportDataSetFromR(“work.GPA1desc”, “desc“);

quit;

data null;
set GPA1desc end = eof ;
i+1;
II=left(put(i,3.));
call symputx(‘var’||II,variable);
call symputx(‘label’||II,label);
if eof then call symputx(‘n’,II);
run;

%macro labelit;
data gpa1;
set gpa1;

    label
%do i=1 %to &n;
&&var&i = &&label&i
%end;
;
run;
%mend;

%labelit