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;

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 2919 views
  • 6 likes
  • 3 in conversation