## caluculed in sas proc

Super Contributor
Posts: 378

# caluculed in sas proc

Hello,

Is it possible to get the differents results for same code and the same input by using

calculated in sas proc ?

(calculated v)*m as T

T can have a different results for the same code and in put ? but with a  very small différence ?

Thank you

Posts: 1,256

## Re: caluculed in sas proc

Yes, this is possible, in particular if the code was executed on different platforms. Perhaps you can expand a little bit on how you obtained the two different results.

Super Contributor
Posts: 378

## Re: caluculed in sas proc

[ Edited ]

Please, why this problem with calculted in sas proc ?

Can you explain more ? is it possible to know the machine and to identify the main raison?

Posts: 5,539

## Re: caluculed in sas proc

The main reason is the representation of floating point numbers in computers. It is only a (very good) approximation. Sometimes, the order of evaluation is enough to make a difference, particularly in calculations involving the sum of numbers with very different scale. Consider for example:

``````data test;
a = 1; b = 1e-14;
run;

proc sql;
select
a + 2*b as c format=e17.,
calculated c - a - b as d format=e12.,
calculated c - b - a as e format=e12.
from test;
quit;

``````
```                                   c             d             e
----------------------------------------------------------------
1.0000000000E+00   9.98401E-15   9.98398E-15
```
PG
Super Contributor
Posts: 378

## Re: caluculed in sas proc

Than you

That's very intersting

To me, if I have (calculated x)*g  as f  is a different of (calculated x)*g  as f  , it will be the platform ? how can i identify the problem in sas log ?

Posts: 1,256

## Re: caluculed in sas proc

PG was faster and gave a nice example.

Yes, numeric representation issues can be one reason for slightly different results of calculations which should actually give identical results from a mathematical point of view. PROC SQL is particularly prone to such issues, because (as you probably know) it sometimes orders the rows of a table in an unpredictable (and platform-dependent) way. Now, if a calculation, let's say a sum, is done like a+b+c+d+e+... or d+a+e+c+b+..., the results obtained by the computer can differ, because rounding errors would accumulate differently depending on the order of the summands, see PG's example.

Super Contributor
Posts: 378

## Re: caluculed in sas proc

Thank you.

It is very interessting.

Please, do you have a good doc for "PROC SQL is particularly prone to such issues, because (as you probably know) it sometimes orders the rows of a table in an unpredictable (and platform-dependent) " ?

I suppose, it depends the platform, so how can I the machine in sas log ? an other means which give the best result ?

To me, if I have (calculated x)*g  as f  is a different of (calculated x)*g  as f  , it will be the platform ? how can i identify the problem in sas log ?

Super User
Posts: 23,771

## Re: caluculed in sas proc

What are you considering large differences? The difference here could be considered the difference between rounding your numbers and calculating or calculating with all the raw data. I wouldn't expect significant differences and I don't think you'd see any information in the log regarding such an issue.

This isn't a SAS SQL issue, its a computer numerical representation issue, Excel will have the same issue, SAS, Python, R ... they all have the same limitations.

Here's the documentation representation of the issue:

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000695157.htm

Posts: 1,256

## Re: caluculed in sas proc

The SAS 9.4 version of the documentation linked by @Reeza has been improved considerably compared to the earlier SAS versions:

http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t...

Super Contributor
Posts: 378

## Re: caluculed in sas proc

Thank you Reeza for your message

As you say

<<it can be  a computer numerical representation issue>>

How can I identify that ?

Super User
Posts: 23,771

## Re: caluculed in sas proc

LineMoon wrote:

How can I identify that ?

You just have.

What are you looking for, the source of the difference is likely numerical precision error. Due you have reasons to believe it might be otherwise? If so, please post your code and some sample data.

If you need examples of numerical precision the documentation has examples in addition to @PGStats example

Super Contributor
Posts: 378

## Re: caluculed in sas proc

[ Edited ]

Thank you Reeza.

My codes is  ==> (calculted x)*y as v

==> sum(v) as col

To reply to your question, which identification I am looking for ?

If i suppose the first rusult (r1) was done by machine A

and the second  rusult (r2) was done by machine B

As r1 is different from r2. I want to identify the machine to see if the different caused by the machine system ?

Thank you

Posts: 5,539

## Re: caluculed in sas proc

When two floating point calculation results are supposed to be the same but differ by a small amount it is usually assumed that the difference is due to rounding error. With IEEE 8 bytes floating point numbers, that small amount rule often translates into abs((r1-r2)/(r1+r2)) < 1e-12.

PG
Super Contributor
Posts: 378

## Re: caluculed in sas proc

That's great PGStats.

is it possible to have an exemple sum_v1 is different from  sum_v2

like this :

proc sql;

sum(v) as sum_v1

from toto

group by y1,y2,y3;

quit;

proc sql;

sum(v) as sum_v2

from toto

group by y1,y2,y3;

quit;