DATA Step, Macro, Functions and more

Strange behaviour of %sysevalf with negative values of the macro variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Strange behaviour of %sysevalf with negative values of the macro variable

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.


Accepted Solutions
Solution
4 weeks ago
Super User
Super User
Posts: 9,441

Re: Strange behaviour of %sysevalf with negative values of the macro variable

[ Edited ]

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


All Replies
Solution
4 weeks ago
Super User
Super User
Posts: 9,441

Re: Strange behaviour of %sysevalf with negative values of the macro variable

[ Edited ]

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.

 

Occasional Contributor
Posts: 18

Re: Strange behaviour of %sysevalf with negative values of the macro variable

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. Smiley Happy

Super User
Posts: 6,644

Re: Strange behaviour of %sysevalf with negative values of the macro variable

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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