BookmarkSubscribeRSS Feed
jenim514
Pyrite | Level 9

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);

1 REPLY 1
ballardw
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 383 views
  • 0 likes
  • 2 in conversation