Here's the part of the code transposed that you originally posted. I'll leave the rest up to you.
data data1;
set &data (keep=&yvar &mvar &avar &cvar &cens);
run;
%if &interaction=true %then %do;
data data1;
set data1;
int=&avar*&mvar;
run;
%end;
%if (&cvar^= & &casecontrol=false) | (&cvar^= &
&casecontrol=) %then %do;
%LET cvars= &cvar;
%LET i =1;
%DO %UNTIL(NOT %LENGTH(%SCAN(&cvars,&i))) ;
proc means noprint data=data1;
var %SCAN(&cvars,&i);
output out=data2&i mean=/autoname;
run;
data data2new&i;
set data2&i;
rename %SCAN(&cvars,&i)_mean = mean;
drop _TYPE_ _FREQ_;
run;
proc append base=data3 data=data2new&i;
run;
proc sql;
%LET i=%EVAL(&i+1);
%END;
proc transpose data=data3 out=data2(drop = _name_);
run;
Honestly, that entire process could be removed from the macro loop and done in a single proc means.
The single proc means below replaces most of the code you originally posted.
%let cvars = weight height;
%let n_vars = %sysfunc(countw(&cvars));
%put &cvars.;
%put &n_vars.;
proc means data=sashelp.class noprint;
var &cvars;
output out=data2 (drop= _type_ _freq_) mean=col1-col&n_vars.;
run;
Good Luck!
In general, there is no SAS alternative to PROC IML, but you can do similar calculations in R or Python.
Perhaps some parts of IML code can be "migrated" to other parts of SAS. Please explain what your code is doing, and maybe there are ways to do this without IML.
I don't know anything about causal mediation analysis, but I do know that SAS has PROC CAUSALMED, which you should investigate.
Thank you for your suggestion. I'm aware of the PROC CAUSALMED, but this procedure is not supported with my current SAS version. So I cannot use it.
I attached the data sample and the specific macro I want to modify here.
Hope that someone who knows well PROC IML can help me to change the code to a different procedure.
Many thanks in advance.
Here's the part of the code transposed that you originally posted. I'll leave the rest up to you.
data data1;
set &data (keep=&yvar &mvar &avar &cvar &cens);
run;
%if &interaction=true %then %do;
data data1;
set data1;
int=&avar*&mvar;
run;
%end;
%if (&cvar^= & &casecontrol=false) | (&cvar^= &
&casecontrol=) %then %do;
%LET cvars= &cvar;
%LET i =1;
%DO %UNTIL(NOT %LENGTH(%SCAN(&cvars,&i))) ;
proc means noprint data=data1;
var %SCAN(&cvars,&i);
output out=data2&i mean=/autoname;
run;
data data2new&i;
set data2&i;
rename %SCAN(&cvars,&i)_mean = mean;
drop _TYPE_ _FREQ_;
run;
proc append base=data3 data=data2new&i;
run;
proc sql;
%LET i=%EVAL(&i+1);
%END;
proc transpose data=data3 out=data2(drop = _name_);
run;
Honestly, that entire process could be removed from the macro loop and done in a single proc means.
The single proc means below replaces most of the code you originally posted.
%let cvars = weight height;
%let n_vars = %sysfunc(countw(&cvars));
%put &cvars.;
%put &n_vars.;
proc means data=sashelp.class noprint;
var &cvars;
output out=data2 (drop= _type_ _freq_) mean=col1-col&n_vars.;
run;
Good Luck!
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!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.