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.
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.
run the code with OPTION MPRINT turned on and examine. Or post the log with the option on.
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;
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.
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.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: