I have a sas table which contains paths from my computer. how can I use the table column as parameter for a macro which I need to run for every path?
Call execute
/********************************************************************
Example : Call macro using parameters from data set
********************************************************************/
proc sort data=sashelp.class out=class;
by age sex;
run;
%macro summary(age=, sex=);
proc print data=sashelp.class;
where age=&age and sex="&sex";
run;
%mend;
data sample;
set class;
by age sex;
if last.sex;
string =
catt('%summary(age=', age, ',sex=', sex, ');');
put string;
run;
data _null_;
set sample;
call execute(string);
run;
But then why bother with the macro at all:
data _null_;
set sashelp.class;
call execute('proc print data=sashelp.class;
where age='||strip(put(age,best.))||' and sex="'||strip(sex)|||'";
run;');
run;
That is a stock example for call execute and passing parameters, I would assume that the actual macro the OP is calling is more complicated.
this page contains a macro which reads a data set and calls another macro
using values in each row as parameters for the called macro.
beware of using call execute to generate a macro call without enclosing the macro call in %nrstr
i.e.
call execute(catt('%nrstr(%MyMacro(data=',data,',var=',var
,'))'
));
(did I count and quote all the parentheses correctly?)
Why: this will save your soul when you get around to using this trick
to call a macro which contains complexity: %if %do or symput.
Yes, that is actually to do with the order of the compilation phase. If you call execute a macro with a call symput in, then it only affects the first occurence. So if you doing that multiple times in a macro then it will work, but will only contain the first value. Generally I avoid using macro and call execute, mainly because pretty much anything I do in macro can be done in call execute or vice versa.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.