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
- /
- General Programming
- /
- When using Sum function on dollar amounts addition...

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
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-07-2013 08:27 AM

Im sure this might be an easy question that we cant see right now being in the midst of problem, but we are summing a numeric variable using a number of methods (sum function sql, proc means, data step with retain) by an id.

Looking at the raw data there appears to be nothing beyond two decimal places in the data. We confirm this after getting it in sas by taking the difference of the variable round to 2 places and the variable without rounding and get no differences between the two.

However after we sum by any of the methods and we take the difference between the rounded sum and the actual sum we are getting differences.

We cant figure out why this is happening or if we are causing it somehow.

Thanks

EJ

Accepted Solutions

Solution

10-07-2013
09:05 AM

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

Posted in reply to esjackso

10-07-2013 09:05 AM

http://support.sas.com/techsup/technote/ts654.pdf

b=3FF0000000000000 c=3FEFFFFFFFFFFFFF

b=

All Replies

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

Posted in reply to esjackso

10-07-2013 08:56 AM

Eric, not sure if this is your case, but it has been long known that there could be some precision issue if 'minus' operation or summary with negative numbers involves. Please see the following example:

data _null_;

a=2.16;b=-1.17;

raw_c=sum(a,b);

round_c=round(raw_c,0.01);

put raw_c= round_c=;

if raw_c=round_c then put "equal" ; else put "not equal";

run;

They are indeed not equal to SAS if you put hex20. to check it out. The safe way to deal with it is to use round() to maintain the precision level.

Haikuo

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

Posted in reply to Haikuo

10-07-2013 09:00 AM

Another approach to dealing with the problem:

Multiply all values by 100. Round to the nearest integer. Sum. Divide the sum by 100.

Precision issues are nearly nonexistent when dealing with integers.

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

Posted in reply to Astounding

10-07-2013 09:07 AM

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

Posted in reply to Haikuo

10-07-2013 09:03 AM

Solution

10-07-2013
09:05 AM

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

Posted in reply to esjackso

10-07-2013 09:05 AM

http://support.sas.com/techsup/technote/ts654.pdf

b=3FF0000000000000 c=3FEFFFFFFFFFFFFF

b=

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

Posted in reply to data_null__

10-07-2013 09:11 AM

Bingo!

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

Posted in reply to data_null__

10-07-2013 09:17 AM

Thanks everyone ... I thought it was something like that but I couldnt explain it very well but the technote was perfect

EJ