[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: Rounding
From:       Roger DeAngelis <rogerjdeangelis () GMAIL ! COM>
Date:       2017-03-30 22:40:07
Message-ID: CAOUdXL-AqqA34idubn3iugyAh7nY1-xFnYRE02=uig84vwzR=Q () mail ! gmail ! com
[Download RAW message or body]

There is a small error when you input numbers like 1.11. If you have to sum
a 100s of these imprecise numbers the total dollars will not agree with
decimal total.

However if you convert to integers using my method  the integer total will
tie out and you can then place the decimal point.



On Thu, Mar 30, 2017 at 6:32 PM, Roger DeAngelis <rogerjdeangelis@gmail.com>
wrote:

>
>
> Yes,  best to deal with it at the source.
>
> With dollars and cents bring it in as character, '6954.23', compress out
> the '.' and input 6.
>
> On Thu, Mar 30, 2017 at 6:02 PM, Nordlund, Dan (DSHS/RDA) <
> NordlDJ@dshs.wa.gov> wrote:
>
>> And even there rounding didn't fail.  The imprecision occurred at input.
>>
>>
>>
>> 354  data _null_;
>>
>> 355  x=6494.4999999999999999999;
>>
>> 356  y=round(x);
>>
>> 357  put x= y=;
>>
>> 358  run;
>>
>>
>>
>> x=6494.5 y=6495
>>
>>
>>
>>
>>
>> Dan
>>
>>
>>
>> Daniel Nordlund, PhD
>>
>> Research and Data Analysis Division
>>
>> Services & Enterprise Support Administration
>>
>> Washington State Department of Social and Health Services
>>
>>
>>
>> *From:* SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] *On Behalf Of *Roger
>> DeAngelis
>> *Sent:* Thursday, March 30, 2017 2:26 PM
>>
>> *To:* SAS-L@LISTSERV.UGA.EDU
>> *Subject:* Re: Rounding
>>
>>
>>
>> I don't think anything needs to be corrected, my post was just a FYI.
>>
>> For rounding to fail you would probably need something like
>>
>>
>>
>> data _null_;
>>
>> x=6494.4999999999999999999;
>>
>> y=round(x);
>>
>> put y=;
>>
>> run;quit;
>>
>>
>>
>> Y=6495
>>
>>
>>
>>
>>
>> On Thu, Mar 30, 2017 at 3:06 PM, Nordlund, Dan (DSHS/RDA) <
>> NordlDJ@dshs.wa.gov> wrote:
>>
>> Roger,
>>
>>
>>
>> Is this in response to something I wrote that you believe needs to be
>> corrected?  If so, I missed the issue of concern.
>>
>>
>>
>> Dan
>>
>>
>>
>> Daniel Nordlund, PhD
>>
>> Research and Data Analysis Division
>>
>> Services & Enterprise Support Administration
>>
>> Washington State Department of Social and Health Services
>>
>>
>>
>> *From:* Roger DeAngelis [mailto:rogerjdeangelis@gmail.com]
>> *Sent:* Thursday, March 30, 2017 9:58 AM
>> *To:* Nordlund, Dan (DSHS/RDA)
>> *Cc:* SAS-L@LISTSERV.UGA.EDU
>> *Subject:* Re: Rounding
>>
>>
>>
>> data _null_;
>>
>>
>>
>>   x=6274.4999;
>>
>>   put x hex16.;
>>
>>
>>
>>   /* here is the problem non-terminating mantissa
>>
>>      cannot represent the number exactly - you have lost already
>>
>>   6274.4999
>>
>>   40B8827FF9724745
>>
>>
>>
>>   like 1/3 in decimal (never is exact)
>>
>>    0.3333333333333
>>
>>   */
>>
>>
>>
>>   x=62744999;
>>
>>   put x hex16.;
>>
>>
>>
>>   /* got it exactly
>>
>>   62744999
>>
>>   418DEB4D38000000
>>
>>   */
>>
>>
>>
>>   x=6274.5;
>>
>>   put x hex16.;
>>
>>
>>
>>   /* got it exactly (when mantissa is a power of 2**(-n))
>>
>>   6274.5
>>
>>   40B8828000000000
>>
>>   */
>>
>>
>>
>>   /* possible solution;
>>
>>    summing in the integer domain is exact (given no overflow);
>>
>>    I don not think it has to be this complex;
>>
>>   */
>>
>>
>>
>>   input numchr $9.;
>>
>>   put numchr;
>>
>>   numchr=compress(numchr,'.');
>>
>>   exact_integer=input(numchr,9.);
>>
>>   put exact_integer hex16.;
>>
>>
>>
>>   * in microcode this should be a bit shifting operation and should be
>> exact?;
>>
>>   * never gets into the microcode for a decision;
>>
>>
>>
>>   res=round(exact_integer,10000);
>>
>>   res=res/10000;
>>
>>   put res 9.4;
>>
>>
>>
>> cards4;
>>
>> 6274.4999
>>
>> 6274.5000
>>
>> 6274.5001
>>
>> ;;;;
>>
>> run;quit;
>>
>>
>>
>>
>>
>> On Thu, Mar 30, 2017 at 11:10 AM, Nordlund, Dan (DSHS/RDA) <
>> NordlDJ@dshs.wa.gov> wrote:
>>
>> > -----Original Message-----
>> > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>>
>> > retired mainframer
>> > Sent: Wednesday, March 29, 2017 6:17 PM
>> > To: SAS-L@LISTSERV.UGA.EDU
>> > Subject: Re: Rounding
>> >
>> > > -----Original Message-----
>> > > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>> > Daniel
>> > > Nordlund
>> > > Sent: Wednesday, March 29, 2017 5:08 PM
>> > > To: SAS-L@LISTSERV.UGA.EDU
>> > > Subject: Re: Rounding
>> > >
>> > > On 3/29/2017 4:28 PM, Joe Matise wrote:
>> > > > ROUND(value, multiple to round to)
>> > > >
>> > > > so ROUND(OldVar, 1) is what you want (round to nearest multiple of
>> 1)
>> > > >
>> > > > However, you're welcome to leave that out and simply ROUND(value),
>> if
>> > > > you want to round to the nearest multiple of 1 (integer).
>> > > >
>> > > > Of course, SAS stores floats, not integers, so it's still not
>> guaranteed
>> > > > to actually _be_ an integer when stored (though I think for
>> normal-ish
>> > > > integer values, it will be an exact number).
>> > > >
>> > > > -Joe
>> > > >
>> > > > On Wed, Mar 29, 2017 at 5:54 PM, Randy <randistan69@hotmail.com
>> > > > <mailto:randistan69@hotmail.com>> wrote:
>> > > >
>> > > >     Dear All:
>> > > >        I want to round 6274.7658. I want 6275.  Is this correct?
>> > > >
>> > > >     Data want; set have;
>> > > >     NewVar = Round(OldVar);
>> > > >     run;
>> > > >
>> > > >
>> > >
>> > > Joe,
>> > >
>> > > can you think of any scenario where rounding, as above, would not
>> result
>> > > in an exact integer value?
>> >
>> > While the result should always be an integer, if the argument is a
>> constant
>> > with too many significant digits to the left of the decimal point,
>> there is a
>> > good chance it will not be the expected integer.   For example,
>> >     x = round(123456789012345678901234567890.666666);
>> > will not produce the value 123456789012345678901234567891.  The value
>> will
>> > have the correct order of magnitude but will be an even number which is
>> > probably several thousand away from the expected value.
>>
>> While that is true, it has nothing to do with the round() function. The
>> inaccuracy comes at the point of reading in the number, before it is even
>> passed to the round() function.
>>
>> 1002  data _null_;
>> 1003    x = 123456789012345678901234567890.666666;
>> 1004    put x=best32.;
>> 1005  run;
>>
>> x=123456789012345660285533552640
>>
>>
>> Dan
>>
>> Daniel Nordlund, PhD
>> Research and Data Analysis Division
>> Services & Enterprise Support Administration
>> Washington State Department of Social and Health Services
>>
>>
>>
>>
>>
>
>

[Attachment #3 (text/html)]

<div dir="ltr"><div class="gmail_default" \
style="font-family:monospace,monospace">There is a small error when you input numbers \
like 1.11. If you have to sum a 100s of these imprecise numbers the total dollars \
will not agree with decimal total.</div><div class="gmail_default" \
style="font-family:monospace,monospace"><br></div><div class="gmail_default" \
style="font-family:monospace,monospace">However if you convert to integers using my \
method   the integer total will tie out and you can then place the decimal \
point.</div><div class="gmail_default" \
style="font-family:monospace,monospace"><br></div><div class="gmail_default" \
style="font-family:monospace,monospace">    </div></div><div \
class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 30, 2017 at 6:32 PM, \
Roger DeAngelis <span dir="ltr">&lt;<a href="mailto:rogerjdeangelis@gmail.com" \
target="_blank">rogerjdeangelis@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" \
style="font-family:monospace,monospace"><br></div><div class="gmail_default" \
style="font-family:monospace,monospace"><br></div><div class="gmail_default" \
style="font-family:monospace,monospace">Yes,   best to deal with it at the \
source.</div><div class="gmail_default" \
style="font-family:monospace,monospace"><br></div><div class="gmail_default" \
style="font-family:monospace,monospace">With dollars and cents bring it in as \
character, &#39;6954.23&#39;, compress out the &#39;.&#39; and input \
6.</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div \
class="gmail_quote">On Thu, Mar 30, 2017 at 6:02 PM, Nordlund, Dan (DSHS/RDA) <span \
dir="ltr">&lt;<a href="mailto:NordlDJ@dshs.wa.gov" \
target="_blank">NordlDJ@dshs.wa.gov</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div class="m_4539955247429996687m_6317125867829082730WordSection1">
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">And \
even there rounding didn't fail.   The imprecision occurred at \
input.<u></u><u></u></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> \
<u></u></span></p> <p class="MsoNormal" style="text-autospace:none"><span \
style="font-size:8.0pt;font-family:&quot;SAS Monospace&quot;">354   data \
_null_;<u></u><u></u></span></p> <p class="MsoNormal" \
style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;SAS \
Monospace&quot;">355   x=6494.4999999999999999999;<u></u><u></u></span></p> <p \
class="MsoNormal" style="text-autospace:none"><span \
style="font-size:8.0pt;font-family:&quot;SAS Monospace&quot;">356   \
y=round(x);<u></u><u></u></span></p> <p class="MsoNormal" \
style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;SAS \
Monospace&quot;">357   put x= y=;<u></u><u></u></span></p> <p class="MsoNormal" \
style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;SAS \
Monospace&quot;">358   run;<u></u><u></u></span></p> <p class="MsoNormal" \
style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;SAS \
Monospace&quot;"><u></u>  <u></u></span></p> <p class="MsoNormal" \
style="text-autospace:none"><span style="font-size:8.0pt;font-family:&quot;SAS \
Monospace&quot;">x=6494.5 y=6495<u></u><u></u></span></p><span> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> \
<u></u></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> \
<u></u></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Dan<u></u><u></u></span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> \
<u></u></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Daniel \
Nordlund, PhD<u></u><u></u></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Research \
and Data Analysis Division<u></u><u></u></span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Services \
&amp; Enterprise Support Administration<u></u><u></u></span></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Washington \
State Department of Social and Health Services<u></u><u></u></span></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> \
<u></u></span></p> </span><div style="border:none;border-left:solid blue \
1.5pt;padding:0in 0in 0in 4.0pt"> <div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span \
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span \
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> \
SAS(r) Discussion [mailto:<a href="mailto:SAS-L@LISTSERV.UGA.EDU" \
target="_blank">SAS-L@LISTSERV.UGA.EDU</a><wbr>] <b>On Behalf Of </b>Roger \
DeAngelis<br> <b>Sent:</b> Thursday, March 30, 2017 2:26 PM</span></p><div><div \
class="m_4539955247429996687h5"><br> <b>To:</b> <a \
href="mailto:SAS-L@LISTSERV.UGA.EDU" target="_blank">SAS-L@LISTSERV.UGA.EDU</a><br> \
<b>Subject:</b> Re: Rounding<u></u><u></u></div></div><p></p> </div>
</div><div><div class="m_4539955247429996687h5">
<p class="MsoNormal"><u></u>  <u></u></p>
<div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">I don&#39;t \
think anything needs to be corrected, my post was just a \
FYI.<u></u><u></u></span></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">For rounding \
to fail you would probably need something like<u></u><u></u></span></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;"><u></u>  \
<u></u></span></p> </div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">data \
_null_;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier \
New&quot;">x=6494.4999999999999999999;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier \
New&quot;">y=round(x);</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">put \
y=;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier \
New&quot;">run;quit;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><u></u>  <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier \
New&quot;">Y=6495</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;"><u></u>  \
<u></u></span></p> </div>
</div>
</div>
<div>
<p class="MsoNormal"><u></u>  <u></u></p>
<div>
<p class="MsoNormal">On Thu, Mar 30, 2017 at 3:06 PM, Nordlund, Dan (DSHS/RDA) &lt;<a \
href="mailto:NordlDJ@dshs.wa.gov" target="_blank">NordlDJ@dshs.wa.gov</a>&gt; \
wrote:<u></u><u></u></p> <div>
<div>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Roger,</span><u></u><u></u></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
</span><u></u><u></u></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Is \
this in response to something I wrote that you believe needs to be corrected?   If \
so, I missed  the issue of concern.</span><u></u><u></u></p>
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
</span><u></u><u></u></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Dan</span><u></u><u></u></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
</span><u></u><u></u></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Daniel \
Nordlund, PhD</span><u></u><u></u></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Research \
and Data Analysis Division</span><u></u><u></u></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Services \
&amp; Enterprise Support Administration</span><u></u><u></u></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Washington \
State Department of Social and Health Services</span><u></u><u></u></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
</span><u></u><u></u></p> <div style="border:none;border-left:solid blue \
1.5pt;padding:0in 0in 0in 4.0pt"> <div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span \
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span \
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> Roger \
DeAngelis [mailto:<a href="mailto:rogerjdeangelis@gmail.com" \
target="_blank">rogerjdeangelis@gmail.<wbr>com</a>] <br>
<b>Sent:</b> Thursday, March 30, 2017 9:58 AM<br>
<b>To:</b> Nordlund, Dan (DSHS/RDA)<br>
<b>Cc:</b> <a href="mailto:SAS-L@LISTSERV.UGA.EDU" \
target="_blank">SAS-L@LISTSERV.UGA.EDU</a><br> <b>Subject:</b> Re: \
Rounding</span><u></u><u></u></p> </div>
</div>
<div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">data \
_null_;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
x=6274.4999;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   put x \
hex16.;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   /* here is \
the problem non-terminating mantissa</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">        cannot \
represent the number exactly - you have lost already</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
6274.4999</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
40B8827FF9724745</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   like 1/3 in \
decimal (never is exact)</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">     \
0.3333333333333</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
*/</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
x=62744999;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   put x \
hex16.;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   /* got it \
exactly</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
62744999</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
418DEB4D38000000</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
*/</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
x=6274.5;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   put x \
hex16.;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   /* got it \
exactly (when mantissa is a power of 2**(-n))</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
6274.5</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
40B8828000000000</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
*/</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   /* possible \
solution;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">     summing \
in the integer domain is exact (given no overflow);</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">     I don not \
think it has to be this complex;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
*/</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   input \
numchr $9.;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   put \
numchr;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
numchr=compress(numchr,&#39;.&#39;);</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
exact_integer=input(numchr,9.)<wbr>;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   put \
exact_integer hex16.;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   * in \
microcode this should be a bit shifting operation and should be \
exact?;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   * never \
gets into the microcode for a decision;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
res=round(exact_integer,10000)<wbr>;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   \
res=res/10000;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">   put res \
9.4;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier \
New&quot;">cards4;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier \
New&quot;">6274.4999</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier \
New&quot;">6274.5000</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier \
New&quot;">6274.5001</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier \
New&quot;">;;;;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><span style="font-family:&quot;Courier \
New&quot;">run;quit;</span><u></u><u></u></p> </div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal">  <u></u><u></u></p>
<div>
<p class="MsoNormal">On Thu, Mar 30, 2017 at 11:10 AM, Nordlund, Dan (DSHS/RDA) \
&lt;<a href="mailto:NordlDJ@dshs.wa.gov" target="_blank">NordlDJ@dshs.wa.gov</a>&gt; \
wrote:<u></u><u></u></p> <p class="MsoNormal">&gt; -----Original Message-----<br>
&gt; From: SAS(r) Discussion [mailto:<a href="mailto:SAS-L@LISTSERV.UGA.EDU" \
target="_blank">SAS-L@LISTSERV.UGA.EDU</a><wbr>] On Behalf Of<u></u><u></u></p> <div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">&gt; retired mainframer<br>
&gt; Sent: Wednesday, March 29, 2017 6:17 PM<br>
&gt; To: <a href="mailto:SAS-L@LISTSERV.UGA.EDU" \
target="_blank">SAS-L@LISTSERV.UGA.EDU</a><br> &gt; Subject: Re: Rounding<br>
&gt;<br>
&gt; &gt; -----Original Message-----<br>
&gt; &gt; From: SAS(r) Discussion [mailto:<a href="mailto:SAS-L@LISTSERV.UGA.EDU" \
target="_blank">SAS-L@LISTSERV.UGA.EDU</a><wbr>] On Behalf Of<br> &gt; Daniel<br>
&gt; &gt; Nordlund<br>
&gt; &gt; Sent: Wednesday, March 29, 2017 5:08 PM<br>
&gt; &gt; To: <a href="mailto:SAS-L@LISTSERV.UGA.EDU" \
target="_blank">SAS-L@LISTSERV.UGA.EDU</a><br> &gt; &gt; Subject: Re: Rounding<br>
&gt; &gt;<br>
&gt; &gt; On 3/29/2017 4:28 PM, Joe Matise wrote:<br>
&gt; &gt; &gt; ROUND(value, multiple to round to)<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; so ROUND(OldVar, 1) is what you want (round to nearest multiple of \
1)<br> &gt; &gt; &gt;<br>
&gt; &gt; &gt; However, you&#39;re welcome to leave that out and simply ROUND(value), \
if<br> &gt; &gt; &gt; you want to round to the nearest multiple of 1 (integer).<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Of course, SAS stores floats, not integers, so it&#39;s still not \
guaranteed<br> &gt; &gt; &gt; to actually _be_ an integer when stored (though I think \
for normal-ish<br> &gt; &gt; &gt; integer values, it will be an exact number).<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; -Joe<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; On Wed, Mar 29, 2017 at 5:54 PM, Randy &lt;<a \
href="mailto:randistan69@hotmail.com" target="_blank">randistan69@hotmail.com</a><br> \
&gt; &gt; &gt; &lt;mailto:<a href="mailto:randistan69@hotmail.com" \
target="_blank">randistan69@hotmail.co<wbr>m</a>&gt;&gt; wrote:<br> &gt; &gt; \
&gt;<br> &gt; &gt; &gt;        Dear All:<br>
&gt; &gt; &gt;            I want to round 6274.7658. I want 6275.   Is this \
correct?<br> &gt; &gt; &gt;<br>
&gt; &gt; &gt;        Data want; set have;<br>
&gt; &gt; &gt;        NewVar = Round(OldVar);<br>
&gt; &gt; &gt;        run;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; Joe,<br>
&gt; &gt;<br>
&gt; &gt; can you think of any scenario where rounding, as above, would not \
result<br> &gt; &gt; in an exact integer value?<br>
&gt;<br>
&gt; While the result should always be an integer, if the argument is a constant<br>
&gt; with too many significant digits to the left of the decimal point, there is \
a<br> &gt; good chance it will not be the expected integer.     For example,<br>
&gt;        x = round(123456789012345678901234<wbr>567890.666666);<br>
&gt; will not produce the value 123456789012345678901234567891<wbr>.   The value \
will<br> &gt; have the correct order of magnitude but will be an even number which \
is<br> &gt; probably several thousand away from the expected value.<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">While that is true, it has nothing \
to do with the round() function. The inaccuracy comes at the point of reading in the \
number, before it is even passed to the round() function.<br> <br>
1002   data _null_;<br>
1003      x = 123456789012345678901234567890<wbr>.666666;<br>
1004      put x=best32.;<br>
1005   run;<br>
<br>
x=1234567890123456602855335526<wbr>40<br>
<br>
<br>
Dan<br>
<br>
Daniel Nordlund, PhD<br>
Research and Data Analysis Division<br>
Services &amp; Enterprise Support Administration<br>
Washington State Department of Social and Health Services<u></u><u></u></p>
</div>
<p class="MsoNormal">  <u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><u></u>  <u></u></p>
</div>
</div></div></div>
</div>
</div>

</blockquote></div><br></div>
</div></div></blockquote></div><br></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic