Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Comparison between two values are Giving wrong res...

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-23-2014 03:06 AM

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 resolvesto 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.**

Accepted Solutions

Solution

04-23-2014
06:24 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Saugata

04-23-2014 06:24 AM

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.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Saugata

04-23-2014 04:36 AM

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.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KurtBremser

04-23-2014 05:57 AM

Hi Kurt,

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

**Regards,**

**Saugata Mukherjee.**

Solution

04-23-2014
06:24 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Saugata

04-23-2014 06:24 AM

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.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KurtBremser

04-23-2014 07:58 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Saugata

04-23-2014 07:09 AM

Try this:

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

%Put I am in the Loop;

%End;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-23-2014 07:59 AM

Thank you