Hello,
I have a macro for serveyfreq that I would like to repeat for 4 levels of &var_name. Therefore I added
%do i=1 %to i=4; ....end (vane_name is a numerical variable); The macro runs well without the do loop but not with the do loop. I appreciate your suggestions to resolve this issue.
* without do loop;
%macro posthoc(var_name);
proc surveyfreq data = data_have VARHEADER = NAMELABEL nosummary;
tables gender/ testp=(50 50) nostd row row(cl) cv chisq;
where &var_name = 1 and condition=1;
weight weight_resc;
run;
quit;
mend posthoc;
* with do loop;
%macro posthoc(var_name);
%do i=1 %to i=4;
proc surveyfreq data = data_have VARHEADER = NAMELABEL nosummary;
tables gender/ testp=(50 50) nostd row row(cl) cv chisq;
where &var_name = 1 and condition=1;
weight weight_resc;
run;
end;
quit;
mend posthoc;
Thanks
Or add two variables to your BY statement instead.
proc surveyfreq data = data_have VARHEADER = NAMELABEL nosummary;
by var_name condition;
tables gender/ testp=(50 50) nostd row row(cl) cv chisq;
where condition=1;
weight weight_resc;
run;
@Emma_at_SAS wrote:
Thanks, Reeza. That was a good idea! I wanted to use two loops for both var_name and condition. Now, I need only one do loop. Would you please help me to figure this out?
Thanks, Reeza. That was a good idea! I wanted to use two loops for both var_name and condition. Now, I need only one do loop. Would you please help me to figure this out?
Or add two variables to your BY statement instead.
proc surveyfreq data = data_have VARHEADER = NAMELABEL nosummary;
by var_name condition;
tables gender/ testp=(50 50) nostd row row(cl) cv chisq;
where condition=1;
weight weight_resc;
run;
@Emma_at_SAS wrote:
Thanks, Reeza. That was a good idea! I wanted to use two loops for both var_name and condition. Now, I need only one do loop. Would you please help me to figure this out?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.