<?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: decimal places Calculaitons in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/decimal-places-Calculaitons/m-p/237811#M43625</link>
    <description>&lt;P&gt;I've experienced similar issues and have solved with the rounding function. &amp;nbsp;Working for the banking industry, &amp;nbsp;financial calculations we perform requires the decimal rounding function even while doing proc compares to provide the tolerances to flag as differences when exceeded.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Dec 2015 14:10:02 GMT</pubDate>
    <dc:creator>kannand</dc:creator>
    <dc:date>2015-12-04T14:10:02Z</dc:date>
    <item>
      <title>decimal places Calculaitons</title>
      <link>https://communities.sas.com/t5/SAS-Programming/decimal-places-Calculaitons/m-p/237767#M43603</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;x = 0.3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;y = 0.1 + 0.1 + 0.1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if x = y then z = "Same values"&lt;/P&gt;&lt;P&gt;else z = "Not"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;still z = "Not".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why is that ??? Please help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 09:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/decimal-places-Calculaitons/m-p/237767#M43603</guid>
      <dc:creator>vandhan</dc:creator>
      <dc:date>2015-12-04T09:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: decimal places Calculaitons</title>
      <link>https://communities.sas.com/t5/SAS-Programming/decimal-places-Calculaitons/m-p/237771#M43607</link>
      <description>Hi,

SAS thinks x &amp;amp; y values are not equal if calculated as per your code, it is because of the precision which takes into account.

data _null_ ;            
 x = 0.3 ;               
 y = 0.1 + 0.1 + 0.1 ;   
 d = x - y ;             
 if x = y then do ;      
    z = "Same values" ;  
 end ;                   
 else z = "Not" ;        
 put x y z d ;           
run ;                    

Log: 0.3 0.3 Not 1.387779E-17

the difference is not 0 so as per SAS x &amp;amp; y values are not equal</description>
      <pubDate>Fri, 04 Dec 2015 10:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/decimal-places-Calculaitons/m-p/237771#M43607</guid>
      <dc:creator>nrk1787db1</dc:creator>
      <dc:date>2015-12-04T10:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: decimal places Calculaitons</title>
      <link>https://communities.sas.com/t5/SAS-Programming/decimal-places-Calculaitons/m-p/237772#M43608</link>
      <description>&lt;P&gt;This is a general thing with decimals. &amp;nbsp;I can't remember the exact terminology for it, but the underlying number is stored with a very tiny part of the number, so you may be comparing 0.3 to 0.3000000000000001, which is different. &amp;nbsp;This is down to the memory storgae of the number and you will come across it a bit. &amp;nbsp;I would always recommend, unless you need to leave a raw number, to round to a know decimal value to omit these kind of problems:&lt;/P&gt;
&lt;PRE&gt;data have;
  x = 0.3;
  y = 0.1 + 0.1 + 0.1;
  if round(x,.1)=round(y,.1) then z="same";
  else z="not";
run;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Dec 2015 10:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/decimal-places-Calculaitons/m-p/237772#M43608</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-04T10:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: decimal places Calculaitons</title>
      <link>https://communities.sas.com/t5/SAS-Programming/decimal-places-Calculaitons/m-p/237781#M43616</link>
      <description>&lt;P&gt;You have encountered a numeric representation issue. Roughly speaking, numeric values are stored in the binary system in the computer's memory, not in the familiar decimal system.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your example:&lt;/P&gt;
&lt;P&gt;0.1 (decimal) = 0.00011001100110011... (binary)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that&amp;nbsp;the binary value is a periodic fraction. For an exact representation the "0011" would need to be repeated infinitely many times, like the 3s in 1/3=0.3333... in the decimal system. Since there are only finitely many bits available to store that value (64 bits on Windows, provided that the numeric variable is stored with the default length of 8 Bytes), the computer has no other choice but to round or truncate the infinite sequence of binary digits. But this produces a small rounding error, a&amp;nbsp;numeric representation error. For the decimal number 0.1 this error is 0.4*2^-56&amp;nbsp;(on Windows), which is approx. 5.55*10^-18. Very small, but, as you know, rounding errors can accumulate easily in calculations and thus lead to surprising results, like 0.1+0.1+0.1 ne 0.3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to see how your numeric values are stored internally, use the BINARY64. or (for a shorter, but equivalent output in hexacedimal notation) HEX16. format (and &lt;STRONG&gt;not&lt;/STRONG&gt; something like 32.30 or BEST32. format):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
x=0.3;
y=0.1+0.1+0.1;
put x binary64.;
put y binary64.;
put x hex16.;
put y hex16.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;0011111111010011001100110011001100110011001100110011001100110011
0011111111010011001100110011001100110011001100110011001100110100
3FD3333333333333
3FD3333333333334
&lt;/PRE&gt;
&lt;P&gt;There you see the difference in the least significant bit.&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Indeed, as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;&amp;nbsp;has&amp;nbsp;suggested,&amp;nbsp;rounding is probably the most important strategy to avoid these errors. The appropriate rounding unit depends on the order of magnitude of the numbers to be rounded, but for most practical applications (i.e., if you're dealing with numbers from, say, 0.000001 to 1000000) I found 10^-9 (1E-9) to be suitable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to dig deeper into the technical details, you could read one of the two standard references on this subject:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://support.sas.com/techsup/technote/ts230.html" target="_blank"&gt;SAS Technical support document TS-230 "Dealing with Numeric Representation Error in SAS Applications"&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://support.sas.com/techsup/technote/ts654.pdf" target="_blank"&gt;SAS Technical support document TS-654 "Numeric Precision 101"&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Conference papers about this topic include:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://www.nesug.org/proceedings/nesug08/ff/ff07.pdf" target="_blank"&gt;Shaoji Xu (2008). Is .1+.2 equal to .3?, NESUG 2008 Proceedings&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://www.lexjansen.com/phuse/2008/cs/cs08.pdf" target="_blank"&gt;Nigel Montgomery (2008). Floating Point error – what, why and how to!!, PhUSE 2008 Proceedings&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings11/275-2011.pdf" target="_blank"&gt;Clarke Thacher (2011). Why .1 + .1 Might Not Equal .2 and Other Pitfalls of Floating-Point Arithmetic, SAS Global Forum 2011 Proceedings&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have given talks about this subject several times in one of my projects in the past and could tell you much more. So, please don't hesitate to ask further&amp;nbsp;questions&amp;nbsp;about it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 11:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/decimal-places-Calculaitons/m-p/237781#M43616</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-12-04T11:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: decimal places Calculaitons</title>
      <link>https://communities.sas.com/t5/SAS-Programming/decimal-places-Calculaitons/m-p/237811#M43625</link>
      <description>&lt;P&gt;I've experienced similar issues and have solved with the rounding function. &amp;nbsp;Working for the banking industry, &amp;nbsp;financial calculations we perform requires the decimal rounding function even while doing proc compares to provide the tolerances to flag as differences when exceeded.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 14:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/decimal-places-Calculaitons/m-p/237811#M43625</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-12-04T14:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: decimal places Calculaitons</title>
      <link>https://communities.sas.com/t5/SAS-Programming/decimal-places-Calculaitons/m-p/237933#M43655</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12567"&gt;@vandhan﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Besides of rounding you can also use the compfuzz() function for such situations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively - and what I would do - you round the result of such operations from the very beginning. Something like:&lt;/P&gt;
&lt;P&gt;y = round(0.1 + 0.1 + 0.1,0.00000001);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Dec 2015 02:58:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/decimal-places-Calculaitons/m-p/237933#M43655</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-12-05T02:58:18Z</dc:date>
    </item>
  </channel>
</rss>

