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