sas

SAS include another SAS script within a macro


I am looking to include one sas program inside the macro written in another sas program. So:

sas_prog1.sas:
data test;
a=1;
run;

sas_prog2.sas:

%macro m2;
%include sas_prog1.sas;
%mend;
%m2;

Does the data step in sas_prog1.sas also need to be wrapped inside a macro?


Solution

  • No - you don't need to. When you use an %include statement, it just essentially writes out all contents in the included file at that location. In your case it just dumps the datastep code and hence it effectively becomes:

    
    %macro m2;
      data test;
       a=1;
      run;
    %mend;
    
    %m2;
    
    

    So you should be good to go.