BookmarkSubscribeRSS Feed
Juanjuan
Fluorite | Level 6

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="&paramcd." %if %upcase(&paramcd)=PNIF or   %upcase(&paramcd)=EQ5D0206 or  %upcase(&paramcd)=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=&paramcd., chgorpchg=&chgorpchg., avisitn=&visn., censornum=&censornum., popoth=&popoth.);
		%end;
9 REPLIES 9
Tom
Super User Tom
Super User

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? 

Tom
Super User Tom
Super User

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.

Juanjuan
Fluorite | Level 6
Thanks a lot for your reply.

1. I am sure that there will always be some records meet that criteria. Because if change to vis_s, the error will disappear and get the expected result. Also, if I put a default value for vis with %let before select, I am afraid the macro value will always the default value.

2. Sorry, it a typo. But even if it’s vis everywhere, still same error will occur.
proc sql noprint;
select avisitn into: vis separated by "-"
from avisit
where paramcd="&paramcd." %if %upcase(&paramcd)=PNIF or %upcase(&paramcd)=EQ5D0206 or %upcase(&paramcd)=SEV %then %do; and avisitn<=8 %end;
;
quit;

%put &vis;

%include mac_a(ancova_wocf_mi.sas);

%do jj=1 %to %sysfunc(countw(&vis,%str(-)));
%let visn=%scan(&vis,&jj, -);
%put &visn;
%ancova_wocf_mi(data=&data., paramcd=&paramcd., chgorpchg=&chgorpchg., avisitn=&visn., censornum=&censornum., popoth=&popoth.);
%end;
Reeza
Super User
Post the error from the code using MPRINT and SYMBOLGEN.
Juanjuan
Fluorite | Level 6
Thanks for your reply.

I really don’t know what’s happened. I just added the codes below and tested again with VIS and VIS_S. Both marco variable names seems fine now with no errors. But I am still worried the error will show again next time.

options mprint symbolgen;

Juanjuan
Fluorite | Level 6

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="&paramcd." %if %upcase(&paramcd)=PNIF or   %upcase(&paramcd)=EQ5D0206 or  %upcase(&paramcd)=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=&paramcd., chgorpchg=&chgorpchg., avisitn=&visn., censornum=&censornum., popoth=&popoth.);
		%end;

_all.PNG

Reeza
Super User

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="&paramcd." %if %upcase(&paramcd)=PNIF or   %upcase(&paramcd)=EQ5D0206 or  %upcase(&paramcd)=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=&paramcd., chgorpchg=&chgorpchg., avisitn=&visn., censornum=&censornum., popoth=&popoth.);
		%end;

_all.PNG


 

Juanjuan
Fluorite | Level 6

Thanks again, I am trying to find the root reason. will update once the issue was fixed. 

Tom
Super User Tom
Super User

@Juanjuan wrote:

_all.PNG


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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 2781 views
  • 2 likes
  • 3 in conversation