turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- caluculed in sas proc

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-13-2016 03:55 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LineMoon

01-13-2016 04:20 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to FreelanceReinhard

01-13-2016 04:37 PM - edited 01-13-2016 04:38 PM

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?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LineMoon

01-13-2016 05:08 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PGStats

01-13-2016 05:45 PM

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 ?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LineMoon

01-13-2016 05:12 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to FreelanceReinhard

01-13-2016 05:44 PM

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 ?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LineMoon

01-13-2016 06:08 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

01-13-2016 06:16 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

01-15-2016 06:26 PM

Thank you Reeza for your message

As you say

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

How can I identify that ?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LineMoon

01-15-2016 10:26 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

01-16-2016 04:42 AM - edited 01-16-2016 04:47 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LineMoon

01-16-2016 02:58 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PGStats

01-16-2016 08:11 PM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LineMoon

01-16-2016 09:35 PM

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