<?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: An oddity Round function:- Can somebody who has used both R and SAS provide some insights in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532812#M16481</link>
    <description>&lt;P&gt;Thank you gentlemen&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; for your responses. I am basically writing to acknowledge and value your time. I am yet to sit with my friend, dig in on the very subject. I will honor the help and will come back with some substance soon as I can. Cheers!&lt;/P&gt;</description>
    <pubDate>Mon, 04 Feb 2019 23:38:44 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-02-04T23:38:44Z</dc:date>
    <item>
      <title>An oddity Round function:- Can somebody who has used both R and SAS provide some insights</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532678#M16475</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can somebody who has used both R and SAS provide some insights&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HEADER class="r_BN D_F W_6D6F p_R P_Zjgzuf ir_0" aria-label="Message 1 of "&gt;
&lt;DIV class="o_h D_F em_0 E_fq7 ek_BB" data-test-id="address-info"&gt;
&lt;DIV class="D_F en_0"&gt;&lt;SPAN class="u_b en_0 C4_Z2aVTcY" data-test-id="message-from"&gt;&lt;SPAN&gt;&lt;SPAN class="D_F rtlI_rtlI_dz_sSg " data-test-id="email-pill"&gt;Scully, Jim&lt;SPAN class="u_N C_Z1VRpVF"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="d_6FIA i_6FIA D_F eo_HB"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="D_F en_0 M_3gJOe A_6Eb4 C_Z1VRpVF" data-test-id="message-date"&gt;&lt;SPAN&gt;Feb 4 at 10:34 AM&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="D_F ab_CI Y_68F4 en_0 cdPFi_ZpQYvz H_6MGW W_6MGW lv_1IWXzk h_Z13pql2 h4_2d9T5e"&gt;Hey Nav,&lt;/DIV&gt;
&lt;/HEADER&gt;
&lt;DIV data-test-id="message-body-container"&gt;
&lt;DIV data-test-id="message-view-body"&gt;
&lt;DIV class="msg-body P_wpofO iy_A" data-test-id="message-view-body-content"&gt;
&lt;DIV class="jb_0 X_6MGW N_6Fd5"&gt;
&lt;DIV&gt;
&lt;DIV id="yiv5119890892"&gt;
&lt;DIV dir="ltr"&gt;
&lt;DIV id="yiv5119890892divtagdefaultwrapper" dir="ltr"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;# In R, the round function rounds floats.&lt;/DIV&gt;
&lt;DIV&gt;# A first example rounds&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;1234&lt;/SPAN&gt;.15 to the 1st decimal place, and returns&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;1234&lt;/SPAN&gt;.&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;round(1234.15, 1)&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;# A second example rounds 12345.15 to the 1st decimal place, and returns 12345.1&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;round(12345.15, 1)&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;# Why does the first example round up, and the second example round down?&lt;/DIV&gt;
# I suspect round-off error in the second example&lt;/DIV&gt;
&lt;DIV&gt;# 12345.15 is not actually stored as&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;12345.15&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;# Rather, it is stored as&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;12345.15&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;plus or minus 0.00000000000001 (large finite number of zeros)&lt;/DIV&gt;
&lt;DIV&gt;# So,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;12345.15&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is actually stored as 12345.149999999999999, which does round to 12345.1&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Can you do a comparative reasoning with SAS?&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 04 Feb 2019 18:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532678#M16475</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-04T18:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: An oddity Round function:- Can somebody who has used both R and SAS provide some insights</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532703#M16476</link>
      <description>&lt;P&gt;SAS numeric are 8-bytes floats.&amp;nbsp; On my windows machine, the largest consecutive integer in SAS is&lt;/P&gt;
&lt;P&gt;9,007,199,254,740,992.&amp;nbsp;&amp;nbsp; (=&amp;nbsp;&amp;nbsp; constant('exactint',8).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Call it&amp;nbsp;&amp;nbsp;X.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, given that data are stored as binary mantissa and binary exponent.&lt;/P&gt;
&lt;OL style="list-style-position: inside;"&gt;
&lt;LI&gt;&amp;nbsp;The only numbers available from X to 2X&amp;nbsp; are the even numbers&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;The only number from 2X to 4X&amp;nbsp; are 0mod4.&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;etc.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Similarly:&lt;/P&gt;
&lt;OL style="list-style-position: inside;"&gt;
&lt;LI&gt;&amp;nbsp;Only integers are available from&amp;nbsp; X down to X/2&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;Only integers and halves from X/2&amp;nbsp; to X/4&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;etc.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;You can work your way down to any base-2 level of precision to show this asymmetry of precision surrounding X times some power of 2.&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;But back to your problem as stated - rounding to the tenth does not produced expected value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename values temp;

data _null_; /* Write out starting and expected round */
  file values;
  put 'datalines;';
  length value  expect  $15;
  do ndigits=1 to 10;
    value=cats(repeat('9',ndigits),.15);
	expect=cats(repeat('9',ndigits),.2);
	put value= expect=;
  end;
  put 'run;';
run;

data oops; /* Read starting and expected value, calculate round and check */
  input value= expect=;
  check=round(value,.1);
  format value expect check comma22.2;
  if check^=expect then flag='OOPS';
  %include values;
run;&lt;BR /&gt;proc print;&lt;BR /&gt;run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice OOPS flag&amp;nbsp; is on for a couple numbers generated above.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:03:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532703#M16476</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-02-04T20:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: An oddity Round function:- Can somebody who has used both R and SAS provide some insights</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532710#M16477</link>
      <description>&lt;P&gt;I think your friend's assumption about representable&amp;nbsp;numbers is incorrect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you are seeing that R (and more recently, Python) adopted the engineering convention of &lt;SPAN&gt;“round to even” when rounding off a 5.&amp;nbsp; See the documentation for the round function in r: ?round&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS rounds 5 away from 0. See&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2011/10/03/rounding-up-rounding-down.html" target="_self"&gt;Rounding up, rounding down&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:14:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532710#M16477</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-02-04T20:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: An oddity Round function:- Can somebody who has used both R and SAS provide some insights</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532723#M16478</link>
      <description>&lt;P&gt;I suspect the "round to even"&amp;nbsp; approach is a&amp;nbsp; way to&amp;nbsp;eliminate bias in rounding for samples with well-behaved distributions at the larger order of magnitude.&amp;nbsp; Ceteris paribus, it would round up and down about the same number of times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But over here in the academic financial analysis world, our users would be mighty surprised, and often annoyed,&amp;nbsp;if 5 were not rounded up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suppose you could work around each of these behaviors to produce the other,&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:25:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532723#M16478</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-02-04T20:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: An oddity Round function:- Can somebody who has used both R and SAS provide some insights</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532743#M16479</link>
      <description>&lt;P&gt;Does R support rounding to values like 0.7?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Such as:&lt;/P&gt;
&lt;PRE&gt;data example;
 do i= 1 to 2 by 0.01;
   y= round(i,0.7);
   output;
 end;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532743#M16479</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-04T20:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: An oddity Round function:- Can somebody who has used both R and SAS provide some insights</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532744#M16480</link>
      <description>&lt;P&gt;Not via the standard round() function. It rounds to powers of 10.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stat.ethz.ch/R-manual/R-devel/library/base/html/Round.html" target="_self"&gt;Here is the round() doc in R.&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 21:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532744#M16480</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-02-04T21:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: An oddity Round function:- Can somebody who has used both R and SAS provide some insights</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532812#M16481</link>
      <description>&lt;P&gt;Thank you gentlemen&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; for your responses. I am basically writing to acknowledge and value your time. I am yet to sit with my friend, dig in on the very subject. I will honor the help and will come back with some substance soon as I can. Cheers!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 23:38:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/532812#M16481</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-04T23:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: An oddity Round function:- Can somebody who has used both R and SAS provide some insights</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/601802#M18354</link>
      <description>&lt;P&gt;&lt;A href="http://theobligatescientist.blogspot.com/2010/02/r-i-still-love-you-but-i-hate-your.html" target="_blank"&gt;http://theobligatescientist.blogspot.com/2010/02/r-i-still-love-you-but-i-hate-your.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2019 20:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/601802#M18354</guid>
      <dc:creator>cminard</dc:creator>
      <dc:date>2019-11-05T20:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: An oddity Round function:- Can somebody who has used both R and SAS provide some insights</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/601837#M18357</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't find "round half to even" in the blog you've posted. I guess it would need some formula along the line of below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input have expected;
  even=mod(int(have)+1,2);
  dot5=abs(mod(have,1))=0.5;
  calculated=round(have) - (even * dot5);
  calculated2= round(have) - mod(int(have)+1,2) * (abs(mod(have,1))=0.5);
  correct= expected=calculated;
  datalines;
23.49 23
23.50 24
23.51 24
23.99 24
24.00 24
24.01 24
24.49 24
24.50 24
24.51 25
-23.49 -23
-23.50 -24
-23.51 -24
-23.99 -24
-24.00 -24
-24.01 -24
-24.49 -24
-24.50 -24
-24.51 -25
;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 438px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33654i2FC8D79F2B30BF4B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2019 22:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/601837#M18357</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-11-05T22:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: An oddity Round function:- Can somebody who has used both R and SAS provide some insights</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/601937#M18360</link>
      <description>&lt;P&gt;No, it's much easier. Just use &lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.2&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n02h2rvq30k869n164ccmcwvhqyk.htm&amp;amp;locale=en" target="_self"&gt;the ROUNDE function.&lt;/A&gt;&amp;nbsp;The 'E' in the name is for "round to Even".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For more information about the round-to-even method, including examples of using the ROUNDE function in SAS, see the article &lt;A href="https://blogs.sas.com/content/iml/2019/11/11/round-to-even.html" target="_self"&gt;"Round to even."&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 15:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/An-oddity-Round-function-Can-somebody-who-has-used-both-R-and/m-p/601937#M18360</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-11-11T15:08:26Z</dc:date>
    </item>
  </channel>
</rss>

