BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Emma_at_SAS
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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?


 

View solution in original post

4 REPLIES 4
Reeza
Super User
Why not just use a BY statement instead?

proc surveyfreq data = data_have VARHEADER = NAMELABEL nosummary;
by var_name;
tables gender/ testp=(50 50) nostd row row(cl) cv chisq;
where condition=1;
weight weight_resc;
run;
quit;
Emma_at_SAS
Lapis Lazuli | Level 10

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?

Reeza
Super User

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?


 

Emma_at_SAS
Lapis Lazuli | Level 10
Thank you! Yes, that worked!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1194 views
  • 4 likes
  • 2 in conversation