Hi,
Asking how to do a macro within a macro! %POP is m y first macro, and %STAT is my macro within....I am asking how I need to se the bold part of this sample code (%STAT) so it executes within %POP. Any help is appreciated!!
%macro pop (flg, trt, num);
Data ADSL;
set ADAM.ADSL (where=(&flg='Y'));
if &trt =: "ADI" then do;
txgrp = "A"; output;
txgrp = "T"; output;
end;
if &trt =: "Placebo" then do;
txgrp = "B"; output;
txgrp = "T"; output;
proc sort; by usubjid;
run;
.........
%macro stat (var);
proc means data= adsl noprint;
by txgrp;
var &var;
output out= stat_&var n=n mean=mean std=std median=median min=min max=max;
run;%mend stat;
%stat (heightbl); %stat (weightbl); %stat (bsabl);
.......
data stats#
length _1 $50 text $200;
set first (in=a)
stat_heightbl (in=b)
stat_weightbl (in=c)
stat_bsabl (in=d);
run;
%mend pop;
%pop(SAFFL, TRT01A, 1);
%pop(ITTFL, TRT01P, 2);
I'm not sure what you actually want for output and find calling a single macro like that for each variable is likely inefficient at best and subject to a number of other problems.
You might consider at single call to the Proc means, such as this:
proc means data = sashelp.class stackodsoutput n mean std median min max; class sex; var height weight; ods output summary=example; ; run;
Which will create a data set with the statistics as variable names and a row variable with the name of the Var variables, one per row, per By or Class. Since you don't show a sort I don't know if you might be having By processing problems.
If this type of out put will work for you then a single macro variable would be used to contain the names of all the variables you want on the VAR statement.
The STACKODSOUTPUT option used to make the statistics as variables will not work with the NOPRINT as the ODS OUTPUT statement requires some output sent to the results.
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.