|
|||
|
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; |
|
|
||||
|
||||
|
|
|
|||
|
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 |
|
|||
|
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; |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |