<?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 precision of a variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/decimal-precision-of-a-variable/m-p/539430#M7065</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264548"&gt;@SaraMed&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the documentation (see link in Tom's reply) you will learn: Neither 556.52 nor 617.78 have an exact internal binary representation, which means that they are stored already with rounding errors. Since both numbers are between 2**&lt;STRONG&gt;9&lt;/STRONG&gt;=512 and 2**10=1024 the least significant bit in the internal binary representation (which can be inspected by means of the BINARY64. or HEX16. formats) corresponds to 2**-(52-&lt;STRONG&gt;9&lt;/STRONG&gt;)=2**-43, leaving a rounding error of up to 2**-44=5.68...E-14. As it turns out, the actual rounding errors of these particular numbers are approx. 2E-14 and 3E-14, respectively, i.e., the value corresponding to the internal representation differs from the true value in the 14th decimal place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the course of calculations with such rounded values the rounding errors easily accumulate, as you know from calculations with rounded decimal values. Indeed, the result in &lt;FONT face="courier new,courier"&gt;var_c&lt;/FONT&gt; differs from the theoretical exact value by almost 2**-55, which (is smaller in &lt;EM&gt;absolute&lt;/EM&gt; terms, but) means a larger &lt;EM&gt;relative&lt;/EM&gt; error than what is present in &lt;FONT face="courier new,courier"&gt;var_a&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;var_b&lt;/FONT&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
var_a = 556.52;
var_b = 617.78000;
var_c= var_a / var_b - 1;
x=-9.91615138075043e-2;
put x hex16.;
put var_c hex16.;
put var_c e20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results in the log:&lt;/P&gt;
&lt;PRE&gt;BFB962A622D338A&lt;STRONG&gt;A&lt;/STRONG&gt;
BFB962A622D338A&lt;STRONG&gt;8&lt;/STRONG&gt;
-9.9161513807504E-02&lt;/PRE&gt;
&lt;P&gt;(The theoretical exact representation would read &lt;FONT face="courier new,courier"&gt;...338A&lt;STRONG&gt;9&lt;/STRONG&gt;C...&lt;/FONT&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, most numeric SAS formats (including the standard&amp;nbsp;&lt;EM&gt;w.d&lt;/EM&gt;&amp;nbsp;format and also COMMAX&lt;EM&gt;w.d&lt;/EM&gt;) perform a little bit of rounding, i.e., they don't show everything what could be extracted from the internal representation (including rounding errors, hence often useless digits). Your result in &lt;FONT face="courier new,courier"&gt;var_c&lt;/FONT&gt; is a case in point: The decimal equivalents of the two internal representations shown above (ending in "...338AA" and "...338A8") and the exact value are&lt;/P&gt;
&lt;PRE&gt;-0.0991615138075042&lt;FONT color="#FF0000"&gt;9233&lt;/FONT&gt;...
-0.0991615138075042&lt;FONT color="#FF0000"&gt;6458&lt;/FONT&gt;...
-0.0991615138075042&lt;STRONG&gt;&lt;FONT color="#008000"&gt;8955&lt;/FONT&gt;&lt;/STRONG&gt;...&lt;/PRE&gt;
&lt;P&gt;So, you're right that even the calculated result could be displayed as&amp;nbsp;&lt;FONT face="courier new,courier"&gt;-0,0991615138075043&lt;/FONT&gt; if there was a suitable format, but there isn't (as far as I know, at least outside of DS2). As you see above, you can get one more significant digit (in this case) with the E20. format than with COMMAX20.16:&amp;nbsp;&lt;FONT face="courier new,courier"&gt;-9.916151380750&lt;STRONG&gt;4&lt;/STRONG&gt;E-02&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Edit: All of the above applies to &lt;EM&gt;Windows&lt;/EM&gt; and &lt;EM&gt;Unix&lt;/EM&gt; platforms.)&lt;/P&gt;</description>
    <pubDate>Thu, 28 Feb 2019 22:53:26 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2019-02-28T22:53:26Z</dc:date>
    <item>
      <title>decimal precision of a variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/decimal-precision-of-a-variable/m-p/539345#M7052</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I have a problem with a decimal variable that is the result of an arithmetic operation.&lt;/P&gt;&lt;P&gt;Suppose this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataout;

	format var_c commax20.16;

	var_a = 556.52;
	var_b = 617.78000;

	var_c = var_a / var_b - 1;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;The value of var_c in the output dataset is -0,0991615138075000, but it should actually be -0,0991615138075043&lt;BR /&gt;How can I make sure that the precision reaches the 16th decimal?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank to all.&lt;/P&gt;&lt;P&gt;Sara&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 28 Feb 2019 15:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/decimal-precision-of-a-variable/m-p/539345#M7052</guid>
      <dc:creator>SaraMed</dc:creator>
      <dc:date>2019-02-28T15:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: decimal precision of a variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/decimal-precision-of-a-variable/m-p/539353#M7053</link>
      <description>&lt;P&gt;SAS stores all numbers as 8 byte floating point. You cannot have more digits of precision than that format allows.&lt;/P&gt;
&lt;P&gt;The FORMAT in SAS is just instructions for how to display the value.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 16:08:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/decimal-precision-of-a-variable/m-p/539353#M7053</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-28T16:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: decimal precision of a variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/decimal-precision-of-a-variable/m-p/539430#M7065</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264548"&gt;@SaraMed&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the documentation (see link in Tom's reply) you will learn: Neither 556.52 nor 617.78 have an exact internal binary representation, which means that they are stored already with rounding errors. Since both numbers are between 2**&lt;STRONG&gt;9&lt;/STRONG&gt;=512 and 2**10=1024 the least significant bit in the internal binary representation (which can be inspected by means of the BINARY64. or HEX16. formats) corresponds to 2**-(52-&lt;STRONG&gt;9&lt;/STRONG&gt;)=2**-43, leaving a rounding error of up to 2**-44=5.68...E-14. As it turns out, the actual rounding errors of these particular numbers are approx. 2E-14 and 3E-14, respectively, i.e., the value corresponding to the internal representation differs from the true value in the 14th decimal place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the course of calculations with such rounded values the rounding errors easily accumulate, as you know from calculations with rounded decimal values. Indeed, the result in &lt;FONT face="courier new,courier"&gt;var_c&lt;/FONT&gt; differs from the theoretical exact value by almost 2**-55, which (is smaller in &lt;EM&gt;absolute&lt;/EM&gt; terms, but) means a larger &lt;EM&gt;relative&lt;/EM&gt; error than what is present in &lt;FONT face="courier new,courier"&gt;var_a&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;var_b&lt;/FONT&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
var_a = 556.52;
var_b = 617.78000;
var_c= var_a / var_b - 1;
x=-9.91615138075043e-2;
put x hex16.;
put var_c hex16.;
put var_c e20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results in the log:&lt;/P&gt;
&lt;PRE&gt;BFB962A622D338A&lt;STRONG&gt;A&lt;/STRONG&gt;
BFB962A622D338A&lt;STRONG&gt;8&lt;/STRONG&gt;
-9.9161513807504E-02&lt;/PRE&gt;
&lt;P&gt;(The theoretical exact representation would read &lt;FONT face="courier new,courier"&gt;...338A&lt;STRONG&gt;9&lt;/STRONG&gt;C...&lt;/FONT&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, most numeric SAS formats (including the standard&amp;nbsp;&lt;EM&gt;w.d&lt;/EM&gt;&amp;nbsp;format and also COMMAX&lt;EM&gt;w.d&lt;/EM&gt;) perform a little bit of rounding, i.e., they don't show everything what could be extracted from the internal representation (including rounding errors, hence often useless digits). Your result in &lt;FONT face="courier new,courier"&gt;var_c&lt;/FONT&gt; is a case in point: The decimal equivalents of the two internal representations shown above (ending in "...338AA" and "...338A8") and the exact value are&lt;/P&gt;
&lt;PRE&gt;-0.0991615138075042&lt;FONT color="#FF0000"&gt;9233&lt;/FONT&gt;...
-0.0991615138075042&lt;FONT color="#FF0000"&gt;6458&lt;/FONT&gt;...
-0.0991615138075042&lt;STRONG&gt;&lt;FONT color="#008000"&gt;8955&lt;/FONT&gt;&lt;/STRONG&gt;...&lt;/PRE&gt;
&lt;P&gt;So, you're right that even the calculated result could be displayed as&amp;nbsp;&lt;FONT face="courier new,courier"&gt;-0,0991615138075043&lt;/FONT&gt; if there was a suitable format, but there isn't (as far as I know, at least outside of DS2). As you see above, you can get one more significant digit (in this case) with the E20. format than with COMMAX20.16:&amp;nbsp;&lt;FONT face="courier new,courier"&gt;-9.916151380750&lt;STRONG&gt;4&lt;/STRONG&gt;E-02&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Edit: All of the above applies to &lt;EM&gt;Windows&lt;/EM&gt; and &lt;EM&gt;Unix&lt;/EM&gt; platforms.)&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 22:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/decimal-precision-of-a-variable/m-p/539430#M7065</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-02-28T22:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: decimal precision of a variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/decimal-precision-of-a-variable/m-p/539525#M7073</link>
      <description>&lt;P&gt;&lt;A href="https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic" target="_blank"&gt;https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 00:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/decimal-precision-of-a-variable/m-p/539525#M7073</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-01T00:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: decimal precision of a variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/decimal-precision-of-a-variable/m-p/539569#M7083</link>
      <description>&lt;P&gt;Well, I think I will use the e20 format. to have the greatest possible precision, also because this rounding creates problems for the subsequent derivative calculations, so to have the smallest gap I have to be as precise as possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your perfect answer!&lt;/P&gt;&lt;P&gt;Sara&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 09:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/decimal-precision-of-a-variable/m-p/539569#M7083</guid>
      <dc:creator>SaraMed</dc:creator>
      <dc:date>2019-03-01T09:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: decimal precision of a variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/decimal-precision-of-a-variable/m-p/539570#M7084</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264548"&gt;@SaraMed&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Well, I think I will use the e20 format. to have the greatest possible precision, also because this rounding creates problems for the subsequent derivative calculations, so to have the smallest gap I have to be as precise as possible.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As long as these subsequent calculations are done in SAS, I would use the internal value (and not a formatted value), i.e., use a SAS dataset to transfer the result. The display format and the accompanying rounding are then irrelevant.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 09:59:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/decimal-precision-of-a-variable/m-p/539570#M7084</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-03-01T09:59:23Z</dc:date>
    </item>
  </channel>
</rss>

