BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kingCobra
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

6 REPLIES 6
Quentin
Super User

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.

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
kingCobra
Obsidian | Level 7

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

ballardw
Super User

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.

Astounding
PROC Star

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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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