Hi All,
I am writing the below %If else statement:
%if (%sysfunc(abs(%sysevalf((47496-49030.8)/49030.8)*100)) gt 12)then %do;
%Put I am in the Loop;
%End;
In log it is showing that:
MLOGIC(S1): %IF condition
(%sysfunc(abs(%sysevalf((47496-49030.8)/49030.8)*100)) gt 12)
is TRUE
Whereas if I check the value of the calculation in the below chunk:
%let a= %sysfunc(abs(%sysevalf((47496-49030.8)/49030.8)*100));
%Put &a.;
Then in the Log it is showing:
SYMBOLGEN: Macro variable A resolves
to 3.130277295087
3.130277295087
So, now my question is how can 3.130277295087 be greater than 12?
I believe this has to do something with how SAS stores the data internally in hexadecimal form. But I am not very sure.
Can anybody shed some light on this one?
Note: If I put a round function in the %If statement, then the result comes out as expected (i.e.False).
Thanks all in advance for your help.
Regards,
Saugata Mukherjee.
Have a look at this:
SAS(R) 9.2 Macro Language: Reference
Right in the middle you have an example of how the %sysevalf function makes it possible.
Without the round function, you have a period in the number, which causes the macro processor to treat the numbers as character strings and do a string comparison, which yields the undesired result.
See the documentation of the %sysevalf function, which will help here.
Hi Kurt,
So, does that mean that it is not possible to do floating point comparison in %If statement?
Regards,
Saugata Mukherjee.
Have a look at this:
SAS(R) 9.2 Macro Language: Reference
Right in the middle you have an example of how the %sysevalf function makes it possible.
Thanks a lot Kurt. Now I have a better understanding of this :smileylaugh:
Try this:
%if %sysevalf((%sysfunc(abs(%sysevalf((47496-49030.8)/49030.8)*100))) gt 12) %then %do;
%Put I am in the Loop;
%End;
Thank you
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.