DATA Step, Macro, Functions and more

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

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 87
Accepted Solution

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

I am getting the following error when I use below code. Can anyone help me debug this.

code...

%if &colloff = 084 %then %do;

  %if &qtr = 2012-11TestNS %then %do;

   libname librf "I:\Valuation\2012-12\ALICO\ProdLM\Programs\Standard\DACRollFrwd\SASLib";

%end;

%else %if &qtr = "2013-02Prod" %then %do;

   libname librf "I:\Valuation\2013-01\ALICO\ProdLM\Programs\Standard\DACRollFrwd\SASLib";

%end;

  %end;

log..

SYMBOLGEN:  Macro variable COLLOFF resolves to 084

SYMBOLGEN:  Macro variable QTR resolves to 2012-11TestNS

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

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

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

       is required. The condition was: %BQUOTE(&qtr) = 2012-11TestNS

       is required. The condition was: %BQUOTE(&qtr) = 2012-11TestNS

       is required. The condition was: %BQUOTE(&qtr) = 2012-11TestNS

ERROR: The macro MASTER will stop executing.

ERROR: The macro MASTER will stop executing.

ERROR: The macro MASTER will stop executing.

801        endsas;


Accepted Solutions
Solution
‎02-19-2013 12:48 PM
PROC Star
Posts: 1,231

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

Hi,

Your are correct that it's a quoting problem.  (Looks like you added %Bquote when you called the macro. )

The macro language thinks the dash in 2012-11TestNS is a subtraction sign, and tries to do subtraction with the character values, and chokes.  So you need to hide (aka mask aka quote) the values.

Suggest you try:

  %if %superq(qtr)=%str(2012-11TestNS) %then %do;

(and same for the second %if, and remove the double quotes from the second %if)

So %superq() hides a dash which results from resolving &qtr at macro execution time, and %str() hides the dash that you can see in 2012-11TestNS at macro compile time.

HTH,

--Q.


View solution in original post


All Replies
Solution
‎02-19-2013 12:48 PM
PROC Star
Posts: 1,231

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

Hi,

Your are correct that it's a quoting problem.  (Looks like you added %Bquote when you called the macro. )

The macro language thinks the dash in 2012-11TestNS is a subtraction sign, and tries to do subtraction with the character values, and chokes.  So you need to hide (aka mask aka quote) the values.

Suggest you try:

  %if %superq(qtr)=%str(2012-11TestNS) %then %do;

(and same for the second %if, and remove the double quotes from the second %if)

So %superq() hides a dash which results from resolving &qtr at macro execution time, and %str() hides the dash that you can see in 2012-11TestNS at macro compile time.

HTH,

--Q.


Frequent Contributor
Posts: 87

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

ah.. thank you so much.. it works..

Frequent Contributor
Posts: 87

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

can i make it as below.. if in case my variable resolves in upper case or lowercase?

%if %superq(qtr)=%str(%upcase(2012-11TESTNS)) %then %do;

PROC Star
Posts: 1,231

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

I think for that you don't need to upcase the right-hand side (because you already typed it in upcase), you need to upcase the left side.  Intead of %superq, you can use %qupcase.  Something like:

4    %macro comp(qtr=);
5      %if %qupcase(&qtr) = %str(2012-20122TESTNS) %then %put Match;
6      %else %put NO MATCH;
7    %mend comp;
8
9    %comp(qtr=2012-20122TESTNS)
Match
10   %comp(qtr=2012-20122testns)
Match
11   %comp(qtr=9999testns)
NO MATCH

Note that with %qupcase, you need the & on &qtr.

--Q.

Frequent Contributor
Posts: 87

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

Thank you.

I was just curious and used %superq in place of %qupcase and got the below error. Can you explain me why the below did not work?

 

31 %macro comp(qtr=);

32 %if %superq(&qtr) = %str(2012-12TESTNS) %then %put Match;

33 %else %put NO MATCH;

34 %mend comp;

35

36 %comp(qtr=2012-12TESTNS)

ERROR: Invalid symbolic variable name 2012-12TESTNS.

NO MATCH

PROC Star
Posts: 1,231

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

Hi,

One oddity of %superq is that the argument is the name of a macro variable, without the & sign in front.

7    %macro comp(qtr=);
8      %if %superq(qtr) = %str(2012-12TESTNS) %then %put Match;
9      %else %put NO MATCH;
10   %mend comp;
11
12   %comp(qtr=2012-12TESTNS)
Match
13   %comp(qtr=2012-12testns)
NO MATCH

An alternative to using %qupcase would be to %upcase the value in a separated %let statement.

16   %macro comp(qtr=);
17     %let qtr=%upcase(&qtr);
18     %if %superq(qtr) = %str(2012-12TESTNS) %then %put Match;
19     %else %put NO MATCH;
20   %mend comp;
21
22   %comp(qtr=2012-12TESTNS)
Match
23   %comp(qtr=2012-12testns)
Match

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 954 views
  • 4 likes
  • 2 in conversation