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
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.
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?
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
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 ?
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.
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 ?
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
The SAS 9.4 version of the documentation linked by @Reeza has been improved considerably compared to the earlier SAS versions:
Thank you Reeza for your message
As you say
<<it can be a computer numerical representation issue>>
How can I identify that ?
@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
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
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.
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;
I don't know. When I run the same code on the same data, on the same machine, I normally expect the same result.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.