BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
petlove
Obsidian | Level 7
 

HI all,

 

I am trying to run multiple programs without calling %run_check for each dataset manually. I have create another macro %prgrun with do loop.:

 

%macro run_check(dsn);

proc printto log="&dsn.log";
run;

proc printto print="&dsn.lst";
run;

%include "&dsn.sas";


%mend;

 

%macro prgrun;
%let dqclist=sd1044#sd1131#sd1121;

%do i= 1 %to %eval(%sysfunc(count(&dqclist,#))+1);
%let dqc=%scan(&dqclist,&i,#);

 

%run_check(/u1/stat/dqc/XXXX/prog/&dqc..);

 

%end;
%mend;

 

options symbolgen mlogic merror serror;
%prgrun;

 

 

I was expecting to run all 3 programs sd1044, sd1131 and sd1121. However, I see that only first program in the loop runs i.e. sd1044.

 

Can you please take look at it? Not sure why other 2 programs don't run?

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Interesting that the log shows the results for assigning a value to a macro variable P21 when none of the code you showed indicates any macro parameter starting with &P.

 

I am suspecting that possibly something in the include file is also using a macro variable &i or a %do I = loop (and the stupid forum is changing lower case  i_ to uppercase I ) . Then when the loop there completes it has a value larger than the &i in the outer loop.

 

View solution in original post

5 REPLIES 5
ballardw
Super User

run the code with OPTION MPRINT turned on and examine. Or post the log with the option on.

petlove
Obsidian | Level 7

here is log:

 

MLOGIC(PRGRUN): Beginning execution.
MLOGIC(PRGRUN): %LET (variable name is DQCLIST)
SYMBOLGEN: Macro variable DQCLIST resolves to sd1044#sd1131#sd1121
MLOGIC(PRGRUN): %DO loop beginning; index variable I; start value is 1; stop value is 3; by value is 1.
MLOGIC(PRGRUN): %LET (variable name is DQC)
SYMBOLGEN: Macro variable DQCLIST resolves to sd1044#sd1131#sd1121
SYMBOLGEN: Macro variable I resolves to 1
MLOGIC(RUN_CHECK): Beginning execution.
SYMBOLGEN: Macro variable DQC resolves to sd1044
MLOGIC(RUN_CHECK): Parameter P21 has value /u1/stat/dqc/XXXX/prog/sd1044.
SYMBOLGEN: Macro variable P21 resolves to /u1/stat/dqc/XXXX/prog/sd1044.
MPRINT(RUN_CHECK): proc printto log="u1/stat/dqc/XXXX/prog/sd1044.log";
MPRINT(RUN_CHECK): run;

 

 

ballardw
Super User

Interesting that the log shows the results for assigning a value to a macro variable P21 when none of the code you showed indicates any macro parameter starting with &P.

 

I am suspecting that possibly something in the include file is also using a macro variable &i or a %do I = loop (and the stupid forum is changing lower case  i_ to uppercase I ) . Then when the loop there completes it has a value larger than the &i in the outer loop.

 

petlove
Obsidian | Level 7

My goodness....I was going crazy on this...

 

Thank you for helping me.

 

Yes, there is &i in other program and that is why it was not going into another loop. I changed it to "J" and now its working.

 

You are my Savior.

 

Thank you so much.

 

 

ballardw
Super User

Welcome to one of the joys of macro programming: Scope of variables.

 

Often declaring variables used strictly locally in a macro such as your loop counters can be remedied by using the %local definition before their use. Best is do that as one of the first lines of a macro:

 

%macro dummy(parameters);

   %local I j k ;

 

   %do I = 1 %to 5;

       <other code>

       %someothermacro (&I, &otherparm);

   %end;

%mend;

Ready to join fellow brilliant minds for the SAS Hackathon?

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