Go Back   Rhinocerus > Newsgroup > Newsgroup comp.soft-sys.sas

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 08-22-2005, 05:08 AM
philbrierley@hotmail.com
Guest
 
Posts: n/a
Default A SAS adding up teaser....

Don't ask how I discovered this...

Sas seems to have problems adding up very simple numbers that add up to
zero. It can give two different results depending on the order of the
numbers (see example1).

Not only that - adding up the same numbers can give a different result
depending on what method is used.




data temp;

/* summing these two arrays should result in the same answer*/
mval_1=-1.3;
mval_2=1.3;
mval_3=-1.3;
mval_4=1.3;
mval_5=-1.3;
mval_6=1.3;

nval_1=1.3;
nval_2=1.3;
nval_3=1.3;
nval_4=-1.3;
nval_5=-1.3;
nval_6=-1.3;

m1 = sum(of mval_1-mval_6);
n1 = sum(of nval_1-nval_6);

/*
m1=0
m2=4.44E-16;
*/

run;



data temp1;

nval_1=-1.3;
nval_2=-1.3;
nval_3=-1.3;
nval_4=-1.3;
nval_5=0;
nval_6=0;
nval_7=1.3;
nval_8=1.3;
nval_9=1.3;
nval_10=0;
nval_11=0;
nval_12=0;

array nn_{12} nval_1-nval_12;

/* these two methods of adding should give the same answer */
n1 = sum(of nval_2-nval_12);

n2=0;
do i=2 to 12;
n2 = n2 + nn_{i};
end;

/*
n1=0
n2=4.44E-16;
*/

run;

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 08-22-2005, 07:08 AM
RolandRB
Guest
 
Posts: n/a
Default Re: A SAS adding up teaser....

This is due to the way floating point numbers are stored by SAS and it
would most likely apply to any other computer language running on the
same platform that stored floating point numbers.

I give this matter some attention on one of my web pages.

http://www.datasavantconsulting.com/.../floating.html

Reply With Quote
  #3 (permalink)  
Old 08-22-2005, 07:16 PM
data _null_;
Guest
 
Posts: n/a
Default Re: A SAS adding up teaser....

This is a good place to start to understand what you have "discovered".

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

philbrierley@hotmail.com wrote:
> Don't ask how I discovered this...

run;

Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Adding rows based on value of another variable Long, Stuart Newsgroup comp.soft-sys.sas 0 11-26-2007 05:25 PM
Re: Adding code into macro Arthur Tabachneck Newsgroup comp.soft-sys.sas 0 09-20-2007 11:07 PM
Re: Adding code into macro Jim Groeneveld Newsgroup comp.soft-sys.sas 0 09-20-2007 08:19 PM
Re: A SAS adding up teaser.... David L Cassell Newsgroup comp.soft-sys.sas 1 08-23-2005 12:42 AM
Re: A SAS adding up teaser.... Dale McLerran Newsgroup comp.soft-sys.sas 0 08-22-2005 07:01 PM



All times are GMT. The time now is 03:38 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.