03-20-2017 11:22 PM - last edited on 03-20-2017 11:49 PM by Reeza
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;
03-21-2017 12:06 AM - edited 03-21-2017 12:13 AM
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 ...
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.