Final code, limited up to 3 factors - you are invited to run it :
%macro meansANOVA(data, totalvars);
/* loop per variable * per factor combination */
data _null_;
class1 = translate("&class",'_',' ');
call symputx('class1',class1);
run;
%do i = 1 %to &totalvars;
proc means data = &data clm mean std stderr;
class &class;
var m&i;
ods out summary=&data._&class1._Means&i;
%end;
%mend meansANOVA;
%macro class_f(factors, nvars, dsn);
/* calculate class = combination of factors and run meansANOVA */
%let nf = %sysfunc(countw(&factors));
/* single factor */
%do i=1 %do &nf;
%let f&i = %scan(&factors, &i);
%let class = &&f&i;
%meansANOVA(&dsn, &nvars);
%end;
/* factors combination */
%if %eval(&nf) = 3 %then %do;
%let class = &f1 &f2; %meansANOVA(&dsn, &nvars);
%let class = &f1 &f3; %meansANOVA(&dsn, &nvars);
%let class = &f2 &f3; %meansANOVA(&dsn, &nvars);
%end; %else
%if %eval(&nf) = 2 %then %do;
%let class = &f1 &f2; %meansANOVA(&dsn, &nvars);
%end;
%mend class_f;
to run the code use:
%class_f(factors, nvars, dsn);
where factors is list of factor variable names seperated by space.
nvars is total number of variables m1 - m&nvars.
dsn is the input dataset name.
I could not run it and hpe you can debug it in case of need.
Did you try using the OUTTABLE option on PROC UNIVARIATE instead?
data have ;
length sample $20 id 8 factor1 factor2 $8 m1-m5 8;
input SAMPLE ID Factor1 Factor2 m1 m2 m3 m4 m5 ;
cards;
NCAT-00121-LC-01 1 S1F2 S2F2 1.1242 0.9108 1.2078 0.9698 1.3997
NCAT-00122-LC-01 2 S1F2 S2F2 0.9238 1.1207 1.3090 1.1214 1.1122
NCAT-00123-LC-01 3 S1F2 S2F2 0.9008 1.0764 1.0655 1.0333 0.9139
NCAT-00125-LC-01 4 S1F2 S2F2 0.9580 1.0099 0.9423 0.7857 0.7829
NCAT-00126-LC-01 5 S1F2 S2F2 0.9911 1.1804 1.1002 0.8962 0.7059
NCAT-00127-LC-01 6 S1F2 S2F2 0.9337 0.7790 0.9809 0.7370 1.1507
NCAT-00128-LC-01 7 S1F2 S2F2 0.8911 0.8306 0.9966 0.9008 1.1129
NCAT-00129-LC-01 8 S1F2 S2F2 0.7743 0.9075 0.9006 0.7545 1.0823
NCAT-00130-LC-01 9 S1F2 S2F2 0.8778 1.2467 1.1428 1.0346 1.1459
NCAT-00131-LC-01 10 S1F2 S2F2 1.1837 0.9635 1.0022 0.9484 1.2579
NCAT-00132-LC-01 11 S1F2 S2F2 1.0674 0.8744 1.1192 1.3258 1.1429
NCAT-00133-LC-01 12 S1F2 S2F2 0.9934 0.9600 0.9988 1.0292 1.1051
NCAT-00134-LC-01 13 S1F2 S2F2 1.2496 1.1706 1.2041 1.2644 1.2787
NCAT-00136-LC-01 14 S1F2 S2F1 0.8153 0.8933 1.3870 1.1998 1.3597
NCAT-00137-LC-01 15 S1F2 S2F1 1.1740 0.9647 1.2137 1.0219 0.9354
NCAT-00138-LC-01 16 S1F2 S2F1 1.0085 0.9042 1.0351 1.0457 0.9850
NCAT-00139-LC-01 17 S1F2 S2F1 0.7983 0.9432 1.0341 1.1845 1.1765
NCAT-00140-LC-01 18 S1F2 S2F1 0.7831 0.9264 0.9654 1.0773 1.1253
NCAT-00141-LC-01 19 S1F2 S2F1 1.1816 1.0947 1.2754 0.9486 1.5532
NCAT-00142-LC-01 20 S1F2 S2F1 0.9824 0.8790 1.0780 0.6967 0.8854
NCAT-00143-LC-01 21 S1F2 S2F1 0.7157 0.8337 0.9973 0.8521 1.0414
NCAT-00144-LC-01 22 S1F2 S2F1 0.8874 0.8590 1.1573 0.8433 1.3164
NCAT-00145-LC-01 23 S1F2 S2F1 0.9024 0.8867 1.0910 1.0155 1.2733
NCAT-00146-LC-01 24 S1F2 S2F1 1.2156 0.8162 1.1029 1.1553 1.2157
NCAT-00147-LC-01 25 S1F2 S2F1 0.9392 1.0253 1.2494 1.2901 1.6068
NCAT-00148-LC-01 26 S1F2 S2F1 0.9844 0.8720 1.1468 0.9804 0.9447
NCAT-00149-LC-01 27 S1F2 S2F1 0.8876 1.1102 1.0676 1.1175 1.0071
NCAT-00150-LC-01 28 S1F2 S2F1 1.0687 0.9460 1.0729 1.2188 1.0361
;
proc univariate data=have outtable=want noprint;
class factor1 factor2 ;
var m1-m5 ;
run;
Here are some of the statistics that it produces.
Obs _VAR_ factor1 factor2 _NOBS_ _MIN_ _MAX_ _STD_
1 m1 S1F2 S2F1 15 0.7157 1.2156 0.15297
2 m1 S1F2 S2F2 13 0.7743 1.2496 0.13365
3 m2 S1F2 S2F1 15 0.8162 1.1102 0.08760
4 m2 S1F2 S2F2 13 0.7790 1.2467 0.14597
5 m3 S1F2 S2F1 15 0.9654 1.3870 0.11468
6 m3 S1F2 S2F2 13 0.9006 1.3090 0.11919
7 m4 S1F2 S2F1 15 0.6967 1.2901 0.16173
8 m4 S1F2 S2F2 13 0.7370 1.3258 0.18038
9 m5 S1F2 S2F1 15 0.8854 1.6068 0.22222
10 m5 S1F2 S2F2 13 0.7059 1.3997 0.19223
Use STACKODS with proc means. And look at CLASSDATA to build custom class levels.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.