DATA Step, Macro, Functions and more

Macro variable not behaving as expected

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

Macro variable not behaving as expected

Hi,

I have a litte macro that reports the agencies that did not complete a submission.

/*get the names of the agencies that did not report*/

sql noprint;

SELECT agency into:missing_agency separated by ' and '

from agency_list;

quit;

SYMBOLGEN:  Macro variable MISSING_agency resolves to agency1 and agency2

/*MACRO TO WRITE THE NAME OF THE NON REPORTERS, IF ANY*/

%macro DidnotReport_AGENCY(missing_agency);

%if &missing_agency = %str() %then %do;

/*%put "Macro Variable is empty";*/

  %end;

  %else %do;

ods region  x=1.0in y=6.5in;

Ods pdf text="^S={font=('Arial' ,10pt, bold ) just=center } Note: %trim(&Missing_agency) did not report this week";

%end;

%mend;

/*RUN THE MACRO*/

%didnotreport_AGENCY(&missing_agency);

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric

  operand is required. The condition was: &missing_agency =


ERROR: The macro DIDNOTREPORT_agency will stop executing.


So I figured it had something to do with the fact that there are two non reporters (macro works well with only one non-reporting agency)

so I reasigned the missing agency to "peter"

  %let missing_agency = peter;

AND THE LOG SAID:

SYMBOLGEN:  Macro variable MISSING_agency resolves to agency1 and agency2


NOTE: A missing equal sign has been inserted after the variable name agency1.

That's interesting!

Why does this happen? And how can I get the name of two agencies to list in the report?


Accepted Solutions
Solution
‎05-30-2014 01:33 PM
Trusted Advisor
Posts: 3,215

Re: Macro variable not behaving as expected

code it this way:
    %if "&missing_agency " = " " %then %do;
By that your value testing will be string based comparison.   

In you original code the string is put into the macro language. You error message is telling you you have a macro language error.
Think of using SAS macro-s you can modify all kind of strings before it is going (reviewed ) into those nested language interpreters.

---->-- ja karman --<-----

View solution in original post


All Replies
Solution
‎05-30-2014 01:33 PM
Trusted Advisor
Posts: 3,215

Re: Macro variable not behaving as expected

code it this way:
    %if "&missing_agency " = " " %then %do;
By that your value testing will be string based comparison.   

In you original code the string is put into the macro language. You error message is telling you you have a macro language error.
Think of using SAS macro-s you can modify all kind of strings before it is going (reviewed ) into those nested language interpreters.

---->-- ja karman --<-----
PROC Star
Posts: 1,325

Re: Macro variable not behaving as expected

Hi,

The word AND is tripping up the implied %eval() in the %IF statement.  You can add macro quoting:

%if %superq(missing_agency)=%str() ...

Or for a utility macro %IsBlank that does this check for you, see:

http://changchung.com/download/022-2009.pdf


Contributor
Posts: 36

Re: Macro variable not behaving as expected

Thanks so much..

Bruce

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 405 views
  • 3 likes
  • 3 in conversation