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

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

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

Hi,

Can anyone help me where I am going wrong with the following code:

%let __tmpmv_dsid = %sysfunc(open(__tmpds_param_check));

%let __tmpmv_num = %sysfunc(varnum(&__tmpmv_dsid,si_unit));

%let __tmpmv_rc  = %sysfunc(fetchobs(&__tmpmv_dsid,1));

%let __tmpmv_val = %sysfunc(getvarc(&__tmpmv_dsid,&__tmpmv_num));

%if not &__tmpmv_val  %then %do;

       %put %str (W)ARNING: SI Unit is not available for parameter: %nrbquote(&param) ;

       %put %str (W)ARNING: Raw unit will be used for CTCAE grade computation;

       %let errcode = %eval(&errcode + 1);

       %let __tmpmv_dsid = %sysfunc(close(&__tmpmv_dsid));

  %end;

  %else %let __tmpmv_dsid = %sysfunc(close(&__tmpmv_dsid));

I am getting ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: not &__tmpmv_val

Thanks in advance.

KC


Accepted Solutions
Solution
‎12-11-2014 04:51 PM
Super User
Posts: 5,085

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

While there is some debate on the best way, this is the way I prefer to check for blank vs. non-blank:

%if %length(&__tmpmv_val)=0 %then %do;

You can actually find an entire paper devoted to this subject.

Good luck.

View solution in original post


All Replies
PROC Star
Posts: 1,233

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

What is the value of &__tmpm_val?

%put >>&__tmpmv_val.<< ;

From the message (and your code), since you are using GETVARC, it could a character value.  The %IF statement is written as if it expects a Boolean value (0/1), or at least an integer that the macro language could treat as a Boolean.

28   %macro Check(p);
29     %if not &p %then %put true;
30     %else %put false;
31   %mend;
32
33   %check(1)
false
34   %check(0)
true
35   %check(9)
false
36   %check(A)   /*Error*/
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: not &p
ERROR: The macro CHECK will stop executing.
37   %check(1.)  /*Error: %eval doesnt know about decimals*/
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: not &p
ERROR: The macro CHECK will stop executing.

Kind Regards,

--Q.

Occasional Contributor
Posts: 15

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

Hi Quentin,

Thanks, for your answer. My &__tmpmv_val is either blank (" ") or a char value (d/L, mg/dL etc).

What is the way out in these cases? Any alternative idea would be great too.

Many thanks,

DS

Super User
Posts: 10,500

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

You can check for most BLANK conditions with

%if %sysevalf(%superq(macrovariablename)=,boolean)=1 %then %do

NOTE: the macrovariable name should not use the &macrovariablename format. Look at the documentation of %superq.

Solution
‎12-11-2014 04:51 PM
Super User
Posts: 5,085

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

While there is some debate on the best way, this is the way I prefer to check for blank vs. non-blank:

%if %length(&__tmpmv_val)=0 %then %do;

You can actually find an entire paper devoted to this subject.

Good luck.

Super User
Posts: 9,681

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

OR

%if  &__tmpmv_val eq %then.........

Occasional Contributor
Posts: 15

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

Thanks to everyone.

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 2726 views
  • 6 likes
  • 5 in conversation