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!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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