BookmarkSubscribeRSS Feed
LineMoon
Lapis Lazuli | Level 10

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

 

23 REPLIES 23
FreelanceReinh
Jade | Level 19

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.

LineMoon
Lapis Lazuli | Level 10

Thank for your message.

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?

 

PGStats
Opal | Level 21

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
LineMoon
Lapis Lazuli | Level 10

 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 ?

FreelanceReinh
Jade | Level 19

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.

LineMoon
Lapis Lazuli | Level 10

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 ?

Reeza
Super User

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

FreelanceReinh
Jade | Level 19

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...

LineMoon
Lapis Lazuli | Level 10

Thank you Reeza for your message

As you say

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

How can I identify that ?

 

 

Reeza
Super User

@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

LineMoon
Lapis Lazuli | Level 10

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

 

PGStats
Opal | Level 21

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
LineMoon
Lapis Lazuli | Level 10

That's great PGStats.

Thank for your exemple.

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;

 

PGStats
Opal | Level 21

I don't know. When I run the same code on the same data, on the same machine, I normally expect the same result.

PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 23 replies
  • 1330 views
  • 11 likes
  • 5 in conversation