Hey!
I'm writing a macro and my current output looks like this:
I'd like to merge those two so that my output looks like this:
This is what my code currently looks like:
The words macro counts the number of variables in vars_icf
%LET M=%WORDS(&vars_icf.);
%Do i=1 %TO &M.;
%Let var1 = %scan (&vars_icf., &i.);
ODS Output summary=output1 (Rename=(&var._N = N &var._NMISS = NMiss));
proc means data=&input. N NMISS;
var &var1.;
run;
ods output close;
ODS Output summary=test;
proc freq data=&input.;
tables &var1. / NOCUM;
run;
ods output close;
I am grateful for any help!
Please post your whole code. The macro definition (%macro and %mend, for %do to work) is missing, as the macro call that activates all this. And I see no %end for the %do.
Ok I added a bit.
%MACRO ICF(vars_icf=, vars_cor=, input=, output=);
%LET M=%WORDS(&vars_icf.);
%DO i=1 %TO &M.;
%Let var1 = %scan (&vars_icf., &i.);
%Let var2 = %scan(&vars_cor., &i.);
ODS Output summary=output1 (RENAME=(&var1._N = N &var1._NMISS = NMiss));
proc means data=&input. N NMISS;
var &var1.;
run;
ods output close;
data output 1_1;
set output1;
format variablenname $20.;
variablenname = "&vars_icf.";
run;
ods output summary=output2;
proc freq data=&input.;
tables &var1. / NOCUM;
run;
ods output close;
set output1;
ods output summary=test2;
proc corr data=&input. PEARSON NOMISS NOPROB NOSIMPLE;
var &var1.;
with &vars_cor.;
ods output close;
data output3_1;
set test2;
%END;
%MEND icf;
%icf(input=multiple_sclerosis, vars_cor=eq5d, vars_icf=d530);
I want to do the following with this macro:
The vars_icf all can be between 0 and 4. So each row stands for 1 variable (d530, d540...) and in the columns, for each var I want
N, NMiss, the absolute and relative frequency and the correlations with the variables of vars_cor.
This is how my preferred output should look like.
Is there a particular reason you're running one variable at a time through all these procedures? Why not do them all at once?
If you're new to SAS, I wouldn't start with macros. There's a lot of 'newer' ways to do things that are a lot more efficient. You can run all variables at once through proc means and proc freq.
It's a worksheet for university and we have to use a macro unfortunately
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.