Import .Rdata to SAS, along with Labels

This post was kindly contributed by From a Logical Point of View » SAS - go there to comment and to read the full post.

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

This post was kindly contributed by From a Logical Point of View » SAS - go there to comment and to read the full post.