The log will show error message when i submitted the code below. But the error will be gone if the macro variable name was changed. What's the reason for this error? the macro used to execute well, but will met this error every day, and i have to change the macro names every time.
1. the first time &vis
2. then i will change it to &vis_t.
proc sql noprint;
select avisitn into: vis separated by "-"
from avisit
where paramcd="¶mcd." %if %upcase(¶mcd)=PNIF or %upcase(¶mcd)=EQ5D0206 or %upcase(¶mcd)=SEV %then %do; and avisitn<=8 %end;
;
quit;
%put &vis;
%include mac_a(ancova_wocf_mi.sas);
%do jj=1 %to %sysfunc(countw(&vis_s,%str(-)));
%let visn=%scan(&vis,&jj, -);
%put &visn;
%ancova_wocf_mi(data=&data., paramcd=¶mcd., chgorpchg=&chgorpchg., avisitn=&visn., censornum=&censornum., popoth=&popoth.);
%end;
I don't see the error message. Which macro variable is it complaining about?
I don't think SAS would generate an error message like that. Perhaps the macro you are calling is generating the error?
A few observations just from looking at the posted code.
1) The SELECT statement will not create VIS if no records meet that criteria. You should add a %LET before the SELECT to set some default value. This will insure the VIS is created.
2) At the top you look to be creating VIS then next you are starting a %DO loop with upper bound based on the number of words in a different macro variable named VIS_S. Then later you are using %SCAN() to pull words from VIS again.
Hello, today the pgm was run in another computer and shows error again, but after rerun the second time, the error disappeared. And the macro name is not resolved from %do statement. Actually, the VIS_S was already resolved to 6-7-8-9-10.
%do jj=1 %to %sysfunc(countw(&vis_s,%str(-)));
%let visn=%scan(&vis_s,&jj, -);
proc sql noprint;
select avisitn into: vis_s separated by "-"
from avisit
where paramcd="¶mcd." %if %upcase(¶mcd)=PNIF or %upcase(¶mcd)=EQ5D0206 or %upcase(¶mcd)=SEV %then %do; and avisitn<=8 %end;
;
quit;
%put &vis_s;
%include mac_a(ancova_wocf_mi.sas);
%do jj=1 %to %sysfunc(countw(&vis_s,%str(-)));
%let visn=%scan(&vis_s,&jj, -);
%put &visn;
%ancova_wocf_mi(data=&data., paramcd=¶mcd., chgorpchg=&chgorpchg., avisitn=&visn., censornum=&censornum., popoth=&popoth.);
%end;
This type of error is usually a small type or a misunderstanding with what's happening and resolving when, ie using CALL EXECUTE and not realizing they don't run until after the data step is complete.
Unfortunately the only way to diagnose this error is to examine all the code and you would have to provide that.
You have nested macros so the issue could be embedded somewhere. I would set MPRINT and SYMBOLGEN and test it until it errors out. The error with that information should give you a pretty good idea of where to look, or which variables to check.
@Juanjuan wrote:
Hello, today the pgm was run in another computer and shows error again, but after rerun the second time, the error disappeared. And the macro name is not resolved from %do statement. Actually, the VIS_S was already resolved to 6-7-8-9-10.
%do jj=1 %to %sysfunc(countw(&vis_s,%str(-))); %let visn=%scan(&vis_s,&jj, -);
proc sql noprint; select avisitn into: vis_s separated by "-" from avisit where paramcd="¶mcd." %if %upcase(¶mcd)=PNIF or %upcase(¶mcd)=EQ5D0206 or %upcase(¶mcd)=SEV %then %do; and avisitn<=8 %end; ; quit; %put &vis_s; %include mac_a(ancova_wocf_mi.sas); %do jj=1 %to %sysfunc(countw(&vis_s,%str(-))); %let visn=%scan(&vis_s,&jj, -); %put &visn; %ancova_wocf_mi(data=&data., paramcd=¶mcd., chgorpchg=&chgorpchg., avisitn=&visn., censornum=&censornum., popoth=&popoth.); %end;
Thanks again, I am trying to find the root reason. will update once the issue was fixed.
@Juanjuan wrote:
The error message you posted has nothing to do with the code you posted. The only way to generate that error message is if you were trying to use the value of a macro variable as the name of the macro variable to use as you %DO loops index variable.
49 %macro test(mvar_name);
50 %do &mvar_name=1 %to 2;
51 %put MVAR_NAME=|&mvar_name| &mvar_name=|&&&mvar_name| ;
52 %end;
53 %mend test;
54 %test(fred);
MVAR_NAME=|fred| fred=|1|
MVAR_NAME=|fred| fred=|2|
55 %test();
ERROR: The macro variable name is either all blank or missing.
ERROR: is an invalid macro variable name for the index variable of the %DO loop.
ERROR: The macro TEST will stop executing.
Perhaps the problem is as simple as an unwanted ampersand?
Setting the SYMBOLGEN option should let you find out what macro variable is being used in this way and make it easier to locate in your code.
56 options symbolgen;
57 %test();
SYMBOLGEN: Macro variable MVAR_NAME resolves to
ERROR: The macro variable name is either all blank or missing.
ERROR: is an invalid macro variable name for the index variable of the %DO loop.
ERROR: The macro TEST will stop executing.
58 options nosymbolgen;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.