As I started scrolling down your code, I was struck that you don't need macros, you don't need macro variables. So, this part of the code is easily replaced with code that has no macro and no macro variables.
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;
Instead of using macros, which you admit you are not good at, you should be using the power of SAS to allow you to do lots of calculations with not a lot of code. It is inefficient to use macros here, because it doesn't take advantage of the power of SAS, and will take longer to program and longer to run. It is also inefficient and confusing to have means as X2 and medians as X3 and min and max are denoted as X4, what sense does any of that make? But for the part of your code above, here is example of how to do all of that part of code without macros and without macro variables, and takes advantage of the power of SAS.
proc means data=yourdatasetname noprint;
class actarmcd grouping; /* More than two CLASS variables can go here if desired */
ways 1;
var yourvariablenames; /* More than one variable name can go here */
output out=stats n= nmiss= mean= std= median= min= max=/autoname;
run;
May I also suggest, as others did, that you write code without macros and without macros variables for one or two instances, get that to work properly, and only then try turning it into a macro. If you can't get code to work properly without macros and without macro variables, it will NEVER work properly with macros and with macro variables. But in this case, macros and macro variables are simply not needed.
... View more