Hi,
I'm not very good with macros and stuck trying to get the below code to run multiple times based on the parameters listed below?
%macro T04_DEM(dsn =, var =, var2 =, var3 =); proc sort data=&dsn.; by actarmcd; run;
Proc Univariate data=&dsn. noprint; Var &var.; by actarmcd ; Output out =Stats_&var. n =X1_Freq nmiss =X1_Miss mean =X2_Mean std =X2_std median=X3_Median min =X4_Min max =X4_Max ; run;
Proc Univariate data=&dsn. noprint; Var &var.; by GROUPING ; Output out = stats2_&var. n =X1_Freq nmiss =X1_Miss mean =X2_Mean std =X2_std median=X3_Median min =X4_Min max =X4_Max ; run;
data stats3_&var.; set stats2_&var.; rename grouping =actarmcd; run;
data table_4_stats_&var.; set Stats_&var. stats3_&var.; run;
ods exclude all ; ods output ttests=ttest_&var.; Proc ttest data=&dsn. ; var &var.;
class actarmcd; run; ods exclude none;
ods exclude all; ods output fishersexact=Fisher_Sex; Proc freq data= &dsn. ;
tables &var2.*actarmcd / fisher out=fish_&var2.; run; ods exclude none;
Proc freq data= &dsn. noprint;
tables &var2.*GROUPING / out=fish2_&var2.; run;
data fish2_&var2.; set fish2_&var2.; rename grouping =actarmcd; run;
data table_4_stats_&var2.; set fish_&var2. fish2_&var2.; run;
ods exclude all; ods output cmh=CMH_&var3. ; Proc freq data= &dsn. ; tables &var3.*actarmcd / CMH out=stats_&var3.; run; ods exclude none;
Proc freq data= &dsn. noprint; tables &var3.*grouping / CMH out=stats2_&var3.; run;
data stats2_&var3.; set stats2_&var3.; rename grouping =actarmcd; run;
data table_4_stats_&var3.; set stats_&var3. stats2_&var3.; run;
%mend T04_DEM;
%T04_DEM (dsn=adsl2, var =age); %T04_DEM (dsn=adsl2, var =bmi); %T04_DEM (dsn=adsl2, var2 =sex); %T04_DEM (dsn=adsl2, var2 =ethnic); %T04_DEM (dsn=adsl2, var3 =BMIGR1);
Running just the first one errors out because there are data steps within the macro that reference var2 but since it isn't in the first macro call, I get the error below
How can I rewrite it so that it runs:
both age and bmi for var
both ethnic and sex for var2
BMIGR1 for var3
... View more