<?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 having problem in put function in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/having-problem-in-put-function/m-p/560287#M10445</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is output and data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="snip 1.PNG" style="width: 213px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29657iDD0BC17249D366FE/image-size/large?v=v2&amp;amp;px=999" role="button" title="snip 1.PNG" alt="snip 1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using "chk=put(mean,8.2);" but still I am getting 5.42 instead of 5.43. is there anything wrong with my SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
    <pubDate>Mon, 20 May 2019 21:01:18 GMT</pubDate>
    <dc:creator>chinna0369</dc:creator>
    <dc:date>2019-05-20T21:01:18Z</dc:date>
    <item>
      <title>having problem in put function</title>
      <link>https://communities.sas.com/t5/New-SAS-User/having-problem-in-put-function/m-p/560287#M10445</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is output and data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="snip 1.PNG" style="width: 213px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29657iDD0BC17249D366FE/image-size/large?v=v2&amp;amp;px=999" role="button" title="snip 1.PNG" alt="snip 1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using "chk=put(mean,8.2);" but still I am getting 5.42 instead of 5.43. is there anything wrong with my SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 21:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/having-problem-in-put-function/m-p/560287#M10445</guid>
      <dc:creator>chinna0369</dc:creator>
      <dc:date>2019-05-20T21:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: having problem in put function</title>
      <link>https://communities.sas.com/t5/New-SAS-User/having-problem-in-put-function/m-p/560293#M10447</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117414"&gt;@chinna0369&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117414"&gt;@chinna0369&lt;/a&gt;&amp;nbsp;wrote:
&lt;P&gt;I am using "chk=put(mean,8.2);" but still I am getting 5.42 instead of 5.43. is there anything wrong with my SAS?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, this can easily happen due to numeric representation issues,&lt;SPAN&gt;&amp;nbsp;i.e. small rounding errors that make numeric values different from what they look like in common display formats.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Example:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
mean=mean(-4.19, 15.04);
true_mean=round(mean,1e-9);
chk=put(mean,8.2);
true_chk=put(true_mean,8.2);
put mean hex16.;
put true_mean hex16.;
run;

proc print data=test noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Log:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;1185  put mean hex16.;
1186  put true_mean hex16.;
1187  run;

4015B3333333333&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;
4015B3333333333&lt;STRONG&gt;&lt;FONT color="#008000"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Output:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;         true_
 mean     mean    chk     true_chk

5.425    5.425    5.42      5.43&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;This is exactly what you observed, although mathematically the mean of -4.19 and 15.04 is, of course, 5.425, which is displayed as 5.43 with format 8.2, but not if the internal value is slightly less than 5.425 because of rounding errors (see log excerpt above).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In the above example even the BEST18. format reveals the rounding error in variable MEAN, but this is not always the case.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 22:09:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/having-problem-in-put-function/m-p/560293#M10447</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-05-20T22:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: having problem in put function</title>
      <link>https://communities.sas.com/t5/New-SAS-User/having-problem-in-put-function/m-p/560297#M10448</link>
      <description>&lt;P&gt;What format is currently assigned to the MEAN variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the actual value for the mean is 5.42456 then a display of 3 decimals would "round" to 5.425 for display&amp;nbsp;but the 8.2 would be 5.42 because the 0.00456 portion is less than .005&lt;/P&gt;
&lt;P&gt;or if the value is something like 5.2499999999 then almost any format that uses fewer than 10 decimal places will round to 5.425 but the 8.2 decimal rounds down at the second decimal.&lt;/P&gt;
&lt;PRE&gt;data junk;
   x=5.424999999999;
   put 'BEST12 format' x=best12.;
   put 'F8.2 format' x= f8.2;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 May 2019 22:11:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/having-problem-in-put-function/m-p/560297#M10448</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-20T22:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: having problem in put function</title>
      <link>https://communities.sas.com/t5/New-SAS-User/having-problem-in-put-function/m-p/560298#M10449</link>
      <description>&lt;P&gt;Hi I have one more question?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a value as "-2.22045E-16" then I want this value as "-2.2E-16". How can I do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 22:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/having-problem-in-put-function/m-p/560298#M10449</guid>
      <dc:creator>chinna0369</dc:creator>
      <dc:date>2019-05-20T22:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: having problem in put function</title>
      <link>https://communities.sas.com/t5/New-SAS-User/having-problem-in-put-function/m-p/560302#M10450</link>
      <description>&lt;P&gt;To &lt;EM&gt;display&lt;/EM&gt; this value differently use a different format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
x=0.2+1.4-1.6;
put x best12.;
put x e8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;-2.22045E-16
-2.2E-16
&lt;/PRE&gt;
&lt;P&gt;Note from the above example that this value (-2**(-52)) frequently occurs as a consequence of numeric representation issues. Appropriate rounding can avoid such values in many cases.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
x=0.2+1.4-1.6;
r=round(x,1e-9);
put x hex16.;
put r hex16.;
put r=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#FF0000"&gt;BCB&lt;/FONT&gt;0000000000000&lt;BR /&gt;&lt;FONT color="#008000"&gt;000&lt;/FONT&gt;0000000000000&lt;BR /&gt;r=0&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 May 2019 22:26:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/having-problem-in-put-function/m-p/560302#M10450</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-05-20T22:26:30Z</dc:date>
    </item>
  </channel>
</rss>

