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

Anyone can help on below query? please...

 

proc sql;
create table Result1 as
select * , 0.75*Numeric1 as Numeric2 format 12.4
from DATA1 where ABC=0 and CBD<=25
and calculated Numeric2 Numeric3;
quit;

 

Outcome of Result1:

Numeric2  Numeric3;

1111           1111 (Not sure why this also appear in my output)

1000           1001

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

This is an artifact caused by the way the computer stores and calculates numbers (binary in 8 bytes, floating point). Whenever decimal fractions are converted to binary, there is a fair chance that the decimal fraction cannot be represented exactly in binary and causes a minimal error of about E-14 (with a number like 1111 that would be about 1E-11).

Your display format limits the decimals to 4 digits, so you can't see that difference.

Use the round() function to get rid of the artifacts:

proc sql;
create table Result1 as
  select
    *,
    round(0.75*Numeric1,.0001) as Numeric2 format 12.4
  from DATA1
  where ABC=0 and CBD<=25
    and calculated Numeric2 < round(Numeric3,0001)
;
quit;

For more detailed information about the issue, google "sas numeric precision".

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

This is an artifact caused by the way the computer stores and calculates numbers (binary in 8 bytes, floating point). Whenever decimal fractions are converted to binary, there is a fair chance that the decimal fraction cannot be represented exactly in binary and causes a minimal error of about E-14 (with a number like 1111 that would be about 1E-11).

Your display format limits the decimals to 4 digits, so you can't see that difference.

Use the round() function to get rid of the artifacts:

proc sql;
create table Result1 as
  select
    *,
    round(0.75*Numeric1,.0001) as Numeric2 format 12.4
  from DATA1
  where ABC=0 and CBD<=25
    and calculated Numeric2 < round(Numeric3,0001)
;
quit;

For more detailed information about the issue, google "sas numeric precision".

CHEESE123
Calcite | Level 5
Thanks!!! Now it is working correctly 🙂

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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