BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DavidLie
Obsidian | Level 7

Hi SAS Experts,

 

I just have a question on specifying series for do loops. Instead of the usual %do n=1 %to..., I would like to specify a series such that it will activate a certain set of numbers (in this case 1, 7,8,10...). But it does not work. Any ways out? 🙂

 

Thanks.

 

Best,
David

 

%let n_MSA=48;

%macro combineMSA(MSA);
%do n=1,7,8,10,11,17,19,23,27,28,29,35,36,38,40,44,46;

data data.diction_MSA&n.; set data.diction;
if MSA ne &n. then delete;
run;

%end;
%mend;
%combineMSA;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Do this in your macro:

%local list i n;
%let list=1 7 8 10 11 17 19 23 27 28 29 35 36 38 40 44 46;
%do i = 1 %to %sysfunc(countw(&list.));
  %let n = %scan(&list.,&i.);
  /* your loop body */
%end;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Do this in your macro:

%local list i n;
%let list=1 7 8 10 11 17 19 23 27 28 29 35 36 38 40 44 46;
%do i = 1 %to %sysfunc(countw(&list.));
  %let n = %scan(&list.,&i.);
  /* your loop body */
%end;
Jagadishkatam
Amethyst | Level 16

Please try the call execute alternate to macro do loop

 

data have;
do n=1,7,8,10,11,17,19,23,27,28,29,35,36,38,40,44,46;
output;
end;
run;


data _null_;
call execute("data data.diction_MSA"||strip(put(n,best.))||"; set data.diction;if MSA ne "||strip(put(n,best.))||" then delete;run;");
run;
Thanks,
Jag
Reeza
Super User


The Macro Appendix has examples of common macro usage, including one with a macro loop.

https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Ap...

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 594 views
  • 4 likes
  • 4 in conversation