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".

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3657 views
  • 1 like
  • 3 in conversation