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
- /
- Base SAS Programming
- /
- Multiplying floating point numbers

Topic Options

- Subscribe to 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-05-2017 09:04 PM

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.

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

DATA test2;

set test;

Mul=num1*num2;

RUN;

Thanks,

Suryakiran

Suryakiran

Accepted Solutions

Solution

07-05-2017
09:44 PM

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

Posted in reply to SuryaKiran

07-05-2017 09:43 PM

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

Suryakiran

All Replies

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

Posted in reply to SuryaKiran

07-05-2017 09:16 PM

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.

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

Posted in reply to WarrenKuhfeld

07-05-2017 09:22 PM

Still the same results after using best16.

Thanks,

Suryakiran

Suryakiran

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

Posted in reply to SuryaKiran

07-05-2017 09:27 PM

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.

Solution

07-05-2017
09:44 PM

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

Posted in reply to SuryaKiran

07-05-2017 09:43 PM

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

Suryakiran

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

Posted in reply to SuryaKiran

07-05-2017 09:46 PM

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.

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

Posted in reply to SuryaKiran

07-05-2017 10:03 PM

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.