<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Discrepancies in final results caused by the way you make the calculations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Discrepancies-in-final-results-caused-by-the-way-you-make-the/m-p/529009#M144468</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11100"&gt;@Zatere&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These are typical rounding errors due to finite-precision arithmetic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simple example: Mathematically, 2/3 + 2/3 = 4/3. But if the operands are stored only with a finite number of decimals, the left-hand side is something like 0.6666...66&lt;STRONG&gt;7&lt;/STRONG&gt; +&amp;nbsp;&lt;SPAN&gt;0.6666...66&lt;STRONG&gt;7&lt;/STRONG&gt; = 1.3333...33&lt;STRONG&gt;4&lt;/STRONG&gt;, whereas the right-hand side is correctly rounded off to 1.3333...33&lt;STRONG&gt;3&lt;/STRONG&gt;, so the results will differ regardless if the finite precision is 12, 25 or even 1000 digits.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In the case of &lt;EM&gt;machine&lt;/EM&gt; arithmetic we're talking about &lt;EM&gt;binary&lt;/EM&gt; digits rather than decimal digits, which makes things even worse, as shown by the example below:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
a=0.1+0.3+0.7;
b=0.1+0.7+0.3;
c=1.1;
if a=b then put 'equal';
else put 'unequal';
put (a b c) (/ =hex16.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;With SAS 9.4 under Windows the result in the log is most likely:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;unequal

a=3FF199999999999A
b=3FF1999999999999
c=3FF199999999999A&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;That is, just because of a different order of summands, the result in &lt;FONT face="courier new,courier"&gt;b&lt;/FONT&gt; is affected by rounding error and thus differs from &lt;FONT face="courier new,courier"&gt;a&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;c&lt;/FONT&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In PROC COMPARE you can use the &lt;A href="https://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=n04714wiqe78lln1dib6b2h0efoq.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n1qxqymug4990kn19wjpm7y98dah" target="_blank"&gt;CRITERION= and METHOD=&lt;/A&gt; options to&amp;nbsp;simplify the result in the presence of such irrelevant small differences.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Jan 2019 10:42:38 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2019-01-22T10:42:38Z</dc:date>
    <item>
      <title>Discrepancies in final results caused by the way you make the calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Discrepancies-in-final-results-caused-by-the-way-you-make-the/m-p/529006#M144467</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would have a general question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have done some changes in the way a program generates results, such as averages, mean etc. For example, I have reduced the number of data steps by combining those many steps in one bigger query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At the end of the process I export the data sets as excel files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I compare the results of the amended code with the original code in excel, I don’t get any discrepancies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, when I compare those in SAS using PROC COMPARE for some of the variables in those data sets I get really small discrepancies like 4.589E-13. The difference is very small, in this example it is only 0.0000000000004589.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any explanation why that is happening? Is it the way that SAS make the calculations or the results are wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 09:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Discrepancies-in-final-results-caused-by-the-way-you-make-the/m-p/529006#M144467</guid>
      <dc:creator>Zatere</dc:creator>
      <dc:date>2019-01-22T09:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Discrepancies in final results caused by the way you make the calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Discrepancies-in-final-results-caused-by-the-way-you-make-the/m-p/529009#M144468</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11100"&gt;@Zatere&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These are typical rounding errors due to finite-precision arithmetic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simple example: Mathematically, 2/3 + 2/3 = 4/3. But if the operands are stored only with a finite number of decimals, the left-hand side is something like 0.6666...66&lt;STRONG&gt;7&lt;/STRONG&gt; +&amp;nbsp;&lt;SPAN&gt;0.6666...66&lt;STRONG&gt;7&lt;/STRONG&gt; = 1.3333...33&lt;STRONG&gt;4&lt;/STRONG&gt;, whereas the right-hand side is correctly rounded off to 1.3333...33&lt;STRONG&gt;3&lt;/STRONG&gt;, so the results will differ regardless if the finite precision is 12, 25 or even 1000 digits.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In the case of &lt;EM&gt;machine&lt;/EM&gt; arithmetic we're talking about &lt;EM&gt;binary&lt;/EM&gt; digits rather than decimal digits, which makes things even worse, as shown by the example below:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
a=0.1+0.3+0.7;
b=0.1+0.7+0.3;
c=1.1;
if a=b then put 'equal';
else put 'unequal';
put (a b c) (/ =hex16.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;With SAS 9.4 under Windows the result in the log is most likely:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;unequal

a=3FF199999999999A
b=3FF1999999999999
c=3FF199999999999A&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;That is, just because of a different order of summands, the result in &lt;FONT face="courier new,courier"&gt;b&lt;/FONT&gt; is affected by rounding error and thus differs from &lt;FONT face="courier new,courier"&gt;a&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;c&lt;/FONT&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In PROC COMPARE you can use the &lt;A href="https://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=n04714wiqe78lln1dib6b2h0efoq.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n1qxqymug4990kn19wjpm7y98dah" target="_blank"&gt;CRITERION= and METHOD=&lt;/A&gt; options to&amp;nbsp;simplify the result in the presence of such irrelevant small differences.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 10:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Discrepancies-in-final-results-caused-by-the-way-you-make-the/m-p/529009#M144468</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-01-22T10:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: Discrepancies in final results caused by the way you make the calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Discrepancies-in-final-results-caused-by-the-way-you-make-the/m-p/529011#M144470</link>
      <description>&lt;P&gt;Thanks a lot! It makes sense!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 11:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Discrepancies-in-final-results-caused-by-the-way-you-make-the/m-p/529011#M144470</guid>
      <dc:creator>Zatere</dc:creator>
      <dc:date>2019-01-22T11:01:20Z</dc:date>
    </item>
  </channel>
</rss>

