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

Hi SAS Users,

 

Today I came across very weird issue in SAS. I just multplied two floating point values and the result is not accurate to actual values.

 

OUTPUT.PNG

 

Capture.PNG

 

If we calculate 0.014x88683.537=1241.569, but SAS give different answer.

 

DATA test2;
set test;
Mul=num1*num2;
RUN;

 

Thanks,
Suryakiran
1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

Figured out the issue: num1 is shown as rounded to 3 decimal values, but when performing the calculation it is not rounded to 3 decimals. 

Thanks,
Suryakiran

View solution in original post

6 REPLIES 6
WarrenKuhfeld
Rhodochrosite | Level 12

Use a format like best16. instead of 5.3 and 12.3 and you will get values closer to the true values.  Multiple them and see if you get something closer to the expected results.

SuryaKiran
Meteorite | Level 14

Still the same results after using best16.

 

OUTPUT.PNG

Thanks,
Suryakiran
WarrenKuhfeld
Rhodochrosite | Level 12

The SAS product will be the same.  The point is if you multiply the numbers together using a calculator, your results will come closer than they did before.

SuryaKiran
Meteorite | Level 14

Figured out the issue: num1 is shown as rounded to 3 decimal values, but when performing the calculation it is not rounded to 3 decimals. 

Thanks,
Suryakiran
WarrenKuhfeld
Rhodochrosite | Level 12

Right.  That is why I wanted you to display the numbers with more precision before multiplying them together to compare to the product that SAS reports.

ChrisNZ
Tourmaline | Level 20

SAS gives the correct answer for your example.

data t;
  x=0.014*88683.537;

  putlog x= 32.16;
run;

x=1241.5695180000000000

 

Go to https://www.wolframalpha.com/input/?i=0.014x88683.537

for a calculation with many more digits than SAS or your calculator will display.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 1506 views
  • 0 likes
  • 3 in conversation