Skip to content

Instantly share code, notes, and snippets.

@statgeek
Last active January 30, 2019 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save statgeek/beb97b1c6d4517dde3b2 to your computer and use it in GitHub Desktop.
Save statgeek/beb97b1c6d4517dde3b2 to your computer and use it in GitHub Desktop.
SAS - Call macro using parameters from data set
/********************************************************************
Example : Call macro using parameters from data set
********************************************************************/
*define macro to be called later;
%macro summary(age=, sex=);
proc print data=sashelp.class;
where age=&age and sex="&sex";
run;
%mend;
*sort data to ensure correct order for next steps;
proc sort data=sashelp.class out=class;
by age sex;
run;
*create macro string to be called in next step. Note the macro is called at the last of each reord;
data sample;
set class;
by age sex;
if last.sex;
string =
catt('%summary(age=', age, ',sex=', sex, ');');
put string;
run;
*Call macro - can be done in previous step but broken out here for demonstration purposes;
data _null_;
set sample;
call execute(string);
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment