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

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.

1 ACCEPTED SOLUTION
6 REPLIES 6
Kurt_Bremser
Super User

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.

Saugata
Obsidian | Level 7

Hi Kurt,

So, does that mean that it is not possible to do floating point comparison in %If statement?

Regards,

Saugata Mukherjee.

Saugata
Obsidian | Level 7

Thanks a lot Kurt. Now I have a better understanding of this :smileylaugh:

SKK
Calcite | Level 5 SKK
Calcite | Level 5

Try this:

%if %sysevalf((%sysfunc(abs(%sysevalf((47496-49030.8)/49030.8)*100))) gt 12) %then %do;

      %Put I am in the Loop;
%End;

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!

What is Bayesian Analysis?

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.

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
  • 6 replies
  • 1567 views
  • 6 likes
  • 3 in conversation