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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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;

Anna_nag
Obsidian | Level 7

Thanks!!

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
  • 2 replies
  • 694 views
  • 1 like
  • 2 in conversation