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 🙂

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 784 views
  • 1 like
  • 2 in conversation