<?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 Numeric Formatting Issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Formatting-Issue/m-p/906429#M357916</link>
    <description>&lt;P&gt;I have noticed a discrepancy when applying a format to a mean where the last digit is 5. In the example below two means are calculated, both giving a result of exactly 90.55. However when the results are formatted to 6.1, one mean shows as 90.5 and the other as 90.6.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data problem;
	input gp x;
	datalines;
	1 92.8
	1 93.4
	1 94.6
	1 81.4
	2 90.55
	2 90.55
	2 90.55
	2 90.55
	;
run;
proc means data=problem mean;
	by gp;
	var x;
	output out=means mean=x;
run;
proc print data=means; 
	format x 6.1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The output from this code is as follows:&lt;/P&gt;&lt;PRE&gt;--------------------------------------------- gp=1 ---------------------------------------------

                                      The MEANS Procedure

                                     Analysis Variable : x

                                                  Mean
                                            90.5500000

--------------------------------------------- gp=2 ---------------------------------------------

                                     Analysis Variable : x

                                                  Mean
                                            90.5500000
&amp;#12;
                            Obs    gp    _TYPE_    _FREQ_         x

                             1      1       0         4        90.5
                             2      2       0         4        90.6&lt;/PRE&gt;&lt;P&gt;Can anyone explain this please?&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>Wed, 06 Dec 2023 13:03:40 GMT</pubDate>
    <dc:creator>BertieDark</dc:creator>
    <dc:date>2023-12-06T13:03:40Z</dc:date>
    <item>
      <title>Numeric Formatting Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Formatting-Issue/m-p/906429#M357916</link>
      <description>&lt;P&gt;I have noticed a discrepancy when applying a format to a mean where the last digit is 5. In the example below two means are calculated, both giving a result of exactly 90.55. However when the results are formatted to 6.1, one mean shows as 90.5 and the other as 90.6.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data problem;
	input gp x;
	datalines;
	1 92.8
	1 93.4
	1 94.6
	1 81.4
	2 90.55
	2 90.55
	2 90.55
	2 90.55
	;
run;
proc means data=problem mean;
	by gp;
	var x;
	output out=means mean=x;
run;
proc print data=means; 
	format x 6.1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The output from this code is as follows:&lt;/P&gt;&lt;PRE&gt;--------------------------------------------- gp=1 ---------------------------------------------

                                      The MEANS Procedure

                                     Analysis Variable : x

                                                  Mean
                                            90.5500000

--------------------------------------------- gp=2 ---------------------------------------------

                                     Analysis Variable : x

                                                  Mean
                                            90.5500000
&amp;#12;
                            Obs    gp    _TYPE_    _FREQ_         x

                             1      1       0         4        90.5
                             2      2       0         4        90.6&lt;/PRE&gt;&lt;P&gt;Can anyone explain this please?&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>Wed, 06 Dec 2023 13:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Formatting-Issue/m-p/906429#M357916</guid>
      <dc:creator>BertieDark</dc:creator>
      <dc:date>2023-12-06T13:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Formatting Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Formatting-Issue/m-p/906430#M357917</link>
      <description>&lt;P&gt;This is due to rounding error, which happens when computing means and when changing the number of decimal places. This is usually unavoidable when working with fractions/decimals that are not a negative power of 2, or multiples thereof.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you change the format of X to best32., you will see&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;gp                                   x

 1                    90.5499999999999
 2                               90.55
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and so to round to one decimal place, x for gp=1 is 90.5, while for gp=2 rounded to one decimal place x is 90.6.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really don't want this to happen, and you need x to one decimal place without this rounding error, you can first run this and then to one decimal place you get the same answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data means;
    set means;
    x=round(x,0.01);
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 13:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Formatting-Issue/m-p/906430#M357917</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-12-06T13:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Formatting Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Formatting-Issue/m-p/906441#M357924</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 13:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Formatting-Issue/m-p/906441#M357924</guid>
      <dc:creator>BertieDark</dc:creator>
      <dc:date>2023-12-06T13:45:49Z</dc:date>
    </item>
  </channel>
</rss>

