Hello @LineMoon,
Please see my reply in the separate thread where you posted this question.
As you saw from one of PG's posts in this thread, there are such examples with three summands. This has to do with the fact that the associative law of addition, (a+b)+c=a+(b+c), breaks down indeed when numeric representation issues come into play. This is explained in one of the standard references on the subject, SAS Technical support document TS-230 "Dealing with Numeric Representation Error in SAS Applications...
I believe, the examples of a+b not equal to b+a which @ballardw remembered, were specific to the IBM mainframe environment he worked in.
If you're interested in further "surprising" results which other programmers came across recently, here are three discussions from last month where I contributed detailed answers, including references and general information:
https://communities.sas.com/t5/Base-SAS-Programming/decimal-places-Calculaitons/m-p/237767
https://communities.sas.com/t5/Base-SAS-Programming/ceil-function-bug/m-p/239275
https://communities.sas.com/t5/General-SAS-Programming/Multiplication-Error-After-some-Digit/m-p/239941
"Classical" results include elementary calculations such as:
data _null_;
if 0.1+0.7~=0.8 then put 'This';
if 3*0.3<0.9 then put 'cannot';
if 9.9/3>3.3 then put 'be true!';
run;
In 2012 I observed a case where two identically defined variables in the same data step contained different values (see the other thread).
More recently (2015, with SAS 9.4 on Windows 7) I encountered examples where the internal value of a decimal fraction changed when adding trailing zeros or writing it in exponential notation:
data _null_;
if 0.00001 ne 1.0E-5 then put 'surprise 1';
if 0.00001 = 1E-5 then put 'OK 1';
if 1E-5 ne 1.0E-5 then put 'surprise 2';
if 1.0E-5 = 1.00E-5 then put 'OK 2';
if 1.00E-5 ne 1.000E-5 then put 'surprise 3';
if 1E-5 = 1.000E-5 then put 'OK 3';
if 0.00001 ne 0.0000100000000000000000000 then put 'surprise 4';
run; /* All IF conditions, including the surprising ones, evaluate to true. */
As it turned out, you can write the numeric literals 1.0E-5, 1.00E-5, 1.000E-5, ... with up to 308 zeros (cf. CONSTANT('SMALL')=2.2250738585072E-308). In this sequence, the internal value stored by SAS changes 96 (!) times in a strange pattern between four different binary floating-point representations. In numeric literals without exponential notation it seems that these effects start only when "too many" decimals are involved: e.g. 0.788999999999999757 ne 0.7889999999999997570.
@All: If you encounter a new class of unexpected results in the context of numeric representation in SAS, please let me know.
... View more