Conduct R analysis within SAS

This post was kindly contributed by SAS Programming for Data Mining Applications - go there to comment and to read the full post.



%macro RScript(Rscript);
data _null_;
     file "&Rscript";
     infile cards;
     input;
     put _infile_;
%mend;

 
%macro CallR(Rscript, Rlog);
systask command "C:\Progra~1\R\R-2.8.0\bin\R.exe CMD BATCH --vanilla --quiet
                    &Rscript  &Rlog "
        taskname=rjob1  wait  status=rjobstatus1;
%mend;

/****************************/
data a;
     length i 4;
     array _x{100} x1-x100;
     do i=1 to 300;
        do j=1 to dim(_x); _x[j]=rannor(98765); end;
        output;    drop j;
     end;
run;

proc export data=a  outfile="c:\a.csv"  dbms=csv; run;

%RScript(c:\rscript.r)
cards;
dcsv <- read.csv('c:/a.csv', header=T)
dsvd<-svd(dcsv[,2:101])
dsvd$u[1:5, 1:5]
dsvd$d[1:8]
;
run;

%CallR(c:/rscript.r, c:/rlog1.txt);

data _null_;
     infile "c:\rlog1.txt";
     input;
     put _infile_;
run;

This post was kindly contributed by SAS Programming for Data Mining Applications - go there to comment and to read the full post.