🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

Why can't I embed PROC R in a macro?

User: "Nico Chart_21517"
Altair Employee
Updated by Nico Chart_21517

The SAS language and the R language have very different syntax and semantics so it is not possible to place R procedure calls inside SAS language macro procedures. This may appear to be a limitation but the two languages have different interpretations of special characters and keywords that would cause conflicts with SAS language macro parsing.

For more sophisticated applications you may well wish to use the SAS language to generate a parameterized set of R language statements before executing them. This may involve an external file for example:

data _null_;
  file "Rpgm1.r" recfm=v;
  put "print(source)";
run;

proc r;
  export data=dataset R=source;
  submit;
  source("Rpgm1.r", echo=T)
  endsubmit;
run;

or alternatively using a SAS language macro:

%macro myRmacro(DSN);
data _null_;
  file "Spgm1.sas" recfm=v;
  put 'PROC R;';
  put "EXPORT data=" &DSN " R=source;";
  put 'SUBMIT;';
  put 'print(source)';
  put 'ENDSUBMIT;';
  put 'run;';
run;
%include "Spgm1.sas" / source2;
%mend myRmacro;
%myRmacro("dataset");

 

Find more posts tagged with

Comments

No comments on this post.