BookmarkSubscribeRSS Feed
jaredp
Quartz | Level 8

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


6 REPLIES 6
Haikuo
Onyx | Level 15

%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

jaredp
Quartz | Level 8

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.

Reeza
Super User

Scan through a list..as mentioned in your links.

And bump it up on the ideas list or SASware ballot as well Smiley Happy

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;

jaredp
Quartz | Level 8

Thanks Reeza.  Good idea to add this to the ballot.

I did see that macro solution, but it certainly is not pretty.

jaredp
Quartz | Level 8

Haha, I see I already had my vote added to that idea. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 6 replies
  • 13934 views
  • 4 likes
  • 4 in conversation