For looping over a list of characters, a data null step works fine:
data _null_;
do r="AB", "DE", "XY";
put r=;
end;
run;
But I'm curious if this be replicated in a macro? When I try with the code below, it expects a %to to be paired with the %do:
%macro char_loop;
%do r="AB", "DE", "XY";
%put &r=;
%end;
%mend char_loop;
For anyone interested, there were a couple threads that touch on this topic:
https://communities.sas.com/message/42866#42866
https://communities.sas.com/message/120110#120110
%DO loop is not as nearly robust as its datastep counterpart. No, I don't think you can use the same style of looping.
Haikuo
I've been coming to the same conclusion. If it a macro countapart is possible (and it likely is), the code would likely be painful.
Scan through a list..as mentioned in your links.
And bump it up on the ideas list or SASware ballot as well ![]()
https://communities.sas.com/ideas/1084
%let i=1;
%do %while (%scan(&varlist, &i, " ") ^=%str());
%let var=%scan(&varlist, &i, " ");
%let i=%eval(&i+1);
%end;
Thanks Reeza. Good idea to add this to the ballot.
I did see that macro solution, but it certainly is not pretty.
Haha, I see I already had my vote added to that idea.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.