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;
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;
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;
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;
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...
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!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.