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

Hi all, I have a question with respect to the %sysevalf. I use in a macro programm the %if-condition of the following form:

 

%if %sysevalf(&est)>0.4 %then %do;
....
%end;

 

 

It works fine if &est has positive values, for example 0.312 or 1.214.But if &est is negative, for example -0.091, then I become the error:

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

 

I dont' understand why it could be important if the number in the macro variable is positive or not.

 

Has somebody seen this effect and has an explanation?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Should that not read:

%if %sysevalf(&est. > 0.4, boolean) %then %do;
....
%end;

?

 

Anyways, I highly advise avoiding doing data processing in macro - macro is after all just a text find/replace system and has virtually no concept of data. 

 

Just o add, I think that as sysevalf does floating point calculations, when the var is de-referenced you see:

%syevalf(-0.091)

Which may look like like a calculation to the function, but incomplete.  Just guessing here though, based on the manual:


Syntax

%SYSEVALF(expression<, conversion-type>)

expression

is an arithmetic or logical expression to evaluate.

 

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Should that not read:

%if %sysevalf(&est. > 0.4, boolean) %then %do;
....
%end;

?

 

Anyways, I highly advise avoiding doing data processing in macro - macro is after all just a text find/replace system and has virtually no concept of data. 

 

Just o add, I think that as sysevalf does floating point calculations, when the var is de-referenced you see:

%syevalf(-0.091)

Which may look like like a calculation to the function, but incomplete.  Just guessing here though, based on the manual:


Syntax

%SYSEVALF(expression<, conversion-type>)

expression

is an arithmetic or logical expression to evaluate.

 

DrBoogie
Obsidian | Level 7

Thank You, with %sysevalf(&est>0.4,boolean) it works. However I don't really understand, why there is such a difference between positive and negative values. But SAS is sometimes quite hard to unterstand, so it's OK. 🙂

Astounding
PROC Star

In your original code, %SYSEVALF computed the value before the >

 

Then ....

 

Macro language needed to compare the results.  It will automatically apply %EVAL when making the comparison  in the %IF statement (comparing the results of %SYSEVALF to 0.4).  However, %EVAL does not understand decimal points.  So macro language automatically makes a character comparison, comparing the first character of the %SYSEVALF result to the "0" within "0.4".

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 2538 views
  • 1 like
  • 3 in conversation