Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAS include another SAS script within a macro

Tags:

sas

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?

like image 275
Victor Avatar asked Jun 07 '26 06:06

Victor


2 Answers

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.

like image 53
SAS2Python Avatar answered Jun 10 '26 07:06

SAS2Python


you can include a code in another in writting it to a temp file as character.

filename exec_code temp;
data _null_;
  file exec_code;
  put ' your sas instruction'
  put 'your sas instruction'
run;

and in your macro use an include

%macro mymacro();

%include exec_code;

%mend;
like image 41
William Avatar answered Jun 10 '26 08:06

William