Last active
January 30, 2019 14:27
-
-
Save statgeek/beb97b1c6d4517dde3b2 to your computer and use it in GitHub Desktop.
SAS - Call macro using parameters from data set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************** | |
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