BookmarkSubscribeRSS Feed
Smile_
Calcite | Level 5

I'm studing how to use Macro in sas and learn coding from other people.

I have a question about the do loop for this code I wonder why they need to put loop j=1 to ... because in loop they didn't refer to j .

Anyone could help please?

 

 

%do i = 1 %to %sysfunc(countw(&Component_List,'/'));
   if pay_cd in ( %do j=1 %to %sysfunc(countw(&&&&&&Component_List_Name_&i,'/'));
           %sysfunc(catq('1a',%sysfunc(translate(&&&&&&Component_List_Name_&i,%str(,),%str( )))))
                  %end; )
then Component_1 = "%scan(&Component_List,&i,'/')";
%end;
 

 

2 REPLIES 2
Tom
Super User Tom
Super User

You should probably study a different program.

 

If you can post an example of the values of the miriad macro variables that this program is referencing then perhaps we can make sense of it.

 

I suspect that originally the program looped over the values and then they changed the logic to try to take advantage of the CATQ() function and forgot to remove the loop.  Since generating duplicate lists of codes like

if pay_cd in ( 'A' 'B' 'C' 'A' 'B' 'C' 'A' 'B' 'C') then ...

instead of 

if pay_cd in ( 'A' 'B' 'C' ) then ...

wouldn't actually make the program fail or even change the result they probably never noticed the mistake.

 

 

 

Smile_
Calcite | Level 5

Dear Tom ,Thank you so much.  very understand 🙂

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
  • 2 replies
  • 764 views
  • 1 like
  • 2 in conversation