turn on suggestions

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
- /
- where clause not working

Topic Options

- 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

06-19-2014 08:45 PM

Hi all,

I am working on this program which is giving me outputs for some observations and null values for others. The programs works for values until 1.3 and after that does not produce a output.

Please try putting 1.3 (which works) and 1.4 (doesn't work) in where statement of proc sql.

**Data** A;

do x =**0.1** to 100not working by **0.1**;

output ;

end;

**run**;

**proc** **sql**;

select * from A where x = **1.4**; /* Try the values of 1.3 and 1.4 */

**quit**;

Accepted Solutions

Solution

06-19-2014
09:12 PM

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

Posted in reply to Anna_nag

06-19-2014 09:12 PM

This is caused by the fact that computers store numbers in floating point binary numbers. You cannot represent 1/10th exactly using binary digits. So eventually you see a difference between adding 0.1 multiple times and normal representation of the same number. Use the ROUND() or test for a very small absolute difference instead.

Data _null_;

do x =0.1 to 2 by 0.1;

if x in (1.3,1.4) then put x= 'Not rounded';

if round(x,0.1) in (1.3,1.4) then put x= 'Rounded' ;

end;

run;

All Replies

Solution

06-19-2014
09:12 PM

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

Posted in reply to Anna_nag

06-19-2014 09:12 PM

This is caused by the fact that computers store numbers in floating point binary numbers. You cannot represent 1/10th exactly using binary digits. So eventually you see a difference between adding 0.1 multiple times and normal representation of the same number. Use the ROUND() or test for a very small absolute difference instead.

Data _null_;

do x =0.1 to 2 by 0.1;

if x in (1.3,1.4) then put x= 'Not rounded';

if round(x,0.1) in (1.3,1.4) then put x= 'Rounded' ;

end;

run;

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

06-19-2014 09:27 PM

Thanks!!