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.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: 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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 5160 views
  • 6 likes
  • 5 in conversation