<?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: Rounding error in Proc Tabulate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rounding-error-in-Proc-Tabulate/m-p/857767#M338932</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150208"&gt;@Holger&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am facing a problem with Proc Tabulate.&lt;/P&gt;
&lt;P&gt;I use 9.4 (TS1M7) on&amp;nbsp; the X64_10PRO platform.&lt;/P&gt;
&lt;P&gt;In the SAS datatable that goes into Proc Tabulate there is a value of 2.735. With a format being 8.2 the result in the table generated by the procedure is 2.73 instead of 2.74 which would be expected due to correct rounding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The procedure looks like this:&lt;/P&gt;
&lt;P&gt;proc tabulate data=Mean_and_SD_all;&lt;BR /&gt;class CAT&amp;nbsp;transy methody Dose;&lt;BR /&gt;var value;&lt;BR /&gt;table CAT=''*(transy=''*Dose=''),methody=''*value=''*f=&amp;amp;decimal_val;&lt;BR /&gt;format transy tr. methody mt.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;decimal_val defines a value of 8.2&lt;/P&gt;
&lt;P&gt;The rounding error occurs for "value" where format ist defined as 8.2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I already tried to add "options&amp;nbsp;&lt;SPAN&gt;cmplib=work.functions;" without success.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does anybody have an idea how to solve the problem of false rounding?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Holger&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It may not be false rounding. It may be that the underlying value is&amp;nbsp;2.7349, so if you display it with three decimal places, you get 2.735 while if you display it with two decimal places, it is 2.73.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So first step would be to determine the underlying value of this variable. You can do this by assigning the format best32. to this variable and seeing what the underlying value is. Then, assuming the value is really 2.7349, you have to decide what you really really really want this to appear as. Once you let us know what you want, we can provide further advice and provide code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no global solution to eliminating round-off discrepancies, but there may be a solution if only we knew what the real number was and what you want to do with it.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Feb 2023 15:13:40 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-02-08T15:13:40Z</dc:date>
    <item>
      <title>Rounding error in Proc Tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-error-in-Proc-Tabulate/m-p/857720#M338913</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am facing a problem with Proc Tabulate.&lt;/P&gt;&lt;P&gt;I use 9.4 (TS1M7) on&amp;nbsp; the X64_10PRO platform.&lt;/P&gt;&lt;P&gt;In the SAS datatable that goes into Proc Tabulate there is a value of 2.735. With a format being 8.2 the result in the table generated by the procedure is 2.73 instead of 2.74 which would be expected due to correct rounding.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The procedure looks like this:&lt;/P&gt;&lt;P&gt;proc tabulate data=Mean_and_SD_all;&lt;BR /&gt;class CAT&amp;nbsp;transy methody Dose;&lt;BR /&gt;var value;&lt;BR /&gt;table CAT=''*(transy=''*Dose=''),methody=''*value=''*f=&amp;amp;decimal_val;&lt;BR /&gt;format transy tr. methody mt.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;amp;decimal_val defines a value of 8.2&lt;/P&gt;&lt;P&gt;The rounding error occurs for "value" where format ist defined as 8.2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already tried to add "options&amp;nbsp;&lt;SPAN&gt;cmplib=work.functions;" without success.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Does anybody have an idea how to solve the problem of false rounding?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Holger&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 11:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-error-in-Proc-Tabulate/m-p/857720#M338913</guid>
      <dc:creator>Holger</dc:creator>
      <dc:date>2023-02-08T11:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Rounding error in Proc Tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-error-in-Proc-Tabulate/m-p/857765#M338931</link>
      <description>&lt;P&gt;Just to add some information regarding my problem:: the wrong rounding does not appear for all numbers but only for single data points - and independ of time the program run and the computer I use for calculation regularly for the same data point while for other data points rounding works perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Holger&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 15:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-error-in-Proc-Tabulate/m-p/857765#M338931</guid>
      <dc:creator>Holger</dc:creator>
      <dc:date>2023-02-08T15:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Rounding error in Proc Tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-error-in-Proc-Tabulate/m-p/857767#M338932</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150208"&gt;@Holger&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am facing a problem with Proc Tabulate.&lt;/P&gt;
&lt;P&gt;I use 9.4 (TS1M7) on&amp;nbsp; the X64_10PRO platform.&lt;/P&gt;
&lt;P&gt;In the SAS datatable that goes into Proc Tabulate there is a value of 2.735. With a format being 8.2 the result in the table generated by the procedure is 2.73 instead of 2.74 which would be expected due to correct rounding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The procedure looks like this:&lt;/P&gt;
&lt;P&gt;proc tabulate data=Mean_and_SD_all;&lt;BR /&gt;class CAT&amp;nbsp;transy methody Dose;&lt;BR /&gt;var value;&lt;BR /&gt;table CAT=''*(transy=''*Dose=''),methody=''*value=''*f=&amp;amp;decimal_val;&lt;BR /&gt;format transy tr. methody mt.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;decimal_val defines a value of 8.2&lt;/P&gt;
&lt;P&gt;The rounding error occurs for "value" where format ist defined as 8.2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I already tried to add "options&amp;nbsp;&lt;SPAN&gt;cmplib=work.functions;" without success.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does anybody have an idea how to solve the problem of false rounding?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Holger&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It may not be false rounding. It may be that the underlying value is&amp;nbsp;2.7349, so if you display it with three decimal places, you get 2.735 while if you display it with two decimal places, it is 2.73.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So first step would be to determine the underlying value of this variable. You can do this by assigning the format best32. to this variable and seeing what the underlying value is. Then, assuming the value is really 2.7349, you have to decide what you really really really want this to appear as. Once you let us know what you want, we can provide further advice and provide code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no global solution to eliminating round-off discrepancies, but there may be a solution if only we knew what the real number was and what you want to do with it.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 15:13:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-error-in-Proc-Tabulate/m-p/857767#M338932</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-08T15:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Rounding error in Proc Tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-error-in-Proc-Tabulate/m-p/857778#M338938</link>
      <description>&lt;P&gt;When discussing the displayed value of any a variable you should &lt;STRONG&gt;always mention the format you are looking at.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that your 2.735 value is displayed with either a BEST5. or maybe something like 8.3. So has already been rounded to that third decimal place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; that&amp;nbsp; your underlying value is not actually 2.735 but something that rounds to that when forced to display 3 decimals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 16:03:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-error-in-Proc-Tabulate/m-p/857778#M338938</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-08T16:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: Rounding error in Proc Tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-error-in-Proc-Tabulate/m-p/857826#M338954</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150208"&gt;@Holger&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The name "&lt;SPAN&gt;Mean_and_SD_all" of your analysis dataset suggests that it contains descriptive statistics computed in an earlier step. In this case, even values in the dataset which would &lt;EM&gt;exactly&lt;/EM&gt; equal 2.735 in a hand calculation can differ from this value by a tiny rounding error incurred during the machine calculation &lt;EM&gt;in the binary system&lt;/EM&gt;. This would be a special case of what &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892" target="_blank" rel="noopener"&gt;PaigeMiller&lt;/A&gt; and &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884" target="_blank" rel="noopener"&gt;ballardw&lt;/A&gt; have described.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Example (created with SAS 9.4M5 under Windows)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input dose value;
cards;
1  2.73
1  2.74
2 -3.40
2  8.87
3  0.70
3  1.40
3  0.30
3  8.54
4  0.70
4  0.30
4  1.40
4  8.54
;

proc summary data=test;
by dose;
var value;
output out=stats mean=;
run;

data _null_;
set stats;
put value= value 8.2 value best32. +2 value hex16.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Result in the log:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;value=2.735     2.74                           2.735  4005E147AE147AE2
value=2.735     2.73                2.73499999999999  4005E147AE147AE0
value=2.735     2.73                2.73499999999999  4005E147AE147AE0
value=2.735     2.74                           2.735  4005E147AE147AE1&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;The mathematically exact mean value of variable VALUE in each of the four "dose groups" is 2.735 and this is what the default (BEST12.) format used in the first column ("&lt;FONT face="courier new,courier"&gt;value=2.735&lt;/FONT&gt;") seems to confirm. However, the 8.2 format in the second column shows that something is "wrong" with dose groups 2 and 3, which is clarified by the BEST32. format in the third column. Yet, it's only the HEX16. format in the rightmost column which reveals that also dose group 1 has a problem: The last hexadecimal digit &lt;STRONG&gt;2&lt;/STRONG&gt; resulted from incorrectly rounding up&amp;nbsp;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;FONT color="#999999"&gt;47AE&lt;SPAN&gt;147AE&lt;/SPAN&gt;&lt;SPAN&gt;147AE&lt;/SPAN&gt;&lt;/FONT&gt;... So, the equation&amp;nbsp;&lt;FONT face="courier new,courier"&gt;(2.73+2.74)/2 =&amp;nbsp;2.735&lt;/FONT&gt;&amp;nbsp;is false (!) in SAS (9.4M5 under Windows).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The fact that dose groups 3 and 4 contain &lt;EM&gt;exactly&lt;/EM&gt; the same values -- just in a slightly different order -- demonstrates how easily this type of rounding error can occur.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As a remedy you could try and "clean" the values using the ROUND function with a suitable rounding unit:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set stats;
value=round(value,1e-10);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 19:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-error-in-Proc-Tabulate/m-p/857826#M338954</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-02-08T19:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Rounding error in Proc Tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rounding-error-in-Proc-Tabulate/m-p/858215#M339087</link>
      <description>&lt;P&gt;Thank you very much for your helpful information.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to run your code and received the exactly same results. Thus, I know my installation is OK.&lt;/P&gt;&lt;P&gt;I trusted the automatic rounding of proc tabulate by defining the output format. Most of the times it works well and delivers the expected results. Now, I know that I should better use the round function before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Holger&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 08:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rounding-error-in-Proc-Tabulate/m-p/858215#M339087</guid>
      <dc:creator>Holger</dc:creator>
      <dc:date>2023-02-10T08:37:32Z</dc:date>
    </item>
  </channel>
</rss>

