LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2001, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 14 Jun 2001 16:51:24 -0400
Reply-To:     Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject:      Re: Round up Not down
Comments: To: Dale McLerran <dmclerra@MY-DEJA.COM>
Comments: cc: "tjkohls@VPICORP.COM" <tjkohls@VPICORP.COM>
Content-Type: text/plain; charset="iso-8859-1"

Dale,

I think the rules are that all numbers are given to 4 decimal places both before and after rounding to the nearest 64th. Then for some reason, probably a requirement, values halfway between the rounded points should round up to the higher round point.

Although one can capture the algorithm in code, I think it clearest to do this specialized rounding as a format. For example,

data fmtdata ; fmtname = "myround" ; do x = 18 to 19 by 1/64 ; start = round ( x , .0001 ) ; end = round ( x + 1/128 , .0001 ) ; label = put ( start, 8.4 ) ; eexcl = "Y" ; output ; start = end ; end = round ( x + 1/64 , .0001 ) ; label = put ( end , 8.4 ) ; eexcl = "N" ; output ; end ; run ;

proc format cntlin = fmtdata ; run ;

data _null_ ; x = 18.0703 ; put x= myround. ; run ;

Execution maybe slowed down slightly over a direct formula, but this more than pays for itself since the arbitrary rules are clear and captured in a format outside the main line of code.

Note that if the requirements changed to round up half the time and down the other half it could be easily implemented by a minor change to the format specification.

Ian Whitlock <whitloi1@westat.com>

-----Original Message----- From: Dale McLerran [mailto:dmclerra@MY-DEJA.COM] Sent: Thursday, June 14, 2001 2:07 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Round up Not down

Terry,

Correct me if I am wrong here. As I understand the rules, you have a rounding rule (round to the nearest 1/64th) and a reporting rule (report to the nearest 0.0001 of the rounded value). Now the value 18.0703 is closer to 18.0625 (18 + 4/64) than it is to 18.078125 (18 + 5/64). Thus, if the rules are as stated above, then reporting 18.0625 would be the correct rounded and reported value. Also, I would note that 18.0703 is exactly the mean of 18.0625 and 18.0781. So it is rather arbitrary whether to report 18.0625 or 18.0781 if you are going to the nearest of these values. Why do you think that 18.0781 should be the rounded value? What else do we need to know about your rounding and reporting rules?

Dale

>Date: Thu, 14 Jun 2001 12:37:20 -0500 >Reply-To: Terry J Kohls <tjkohls@VPICORP.COM> >From: Terry J Kohls <tjkohls@VPICORP.COM> >SUBJECTTo: SAS-L@LISTSERV.UGA.EDU > >Hi Folks, > >My figure is 18.0703, and it lies just below the median of 18.0625 and 18.0781. >I want 18.0703 to round up to 18.0781 and not down to 18.0625. How, using the >round function, can I accomplish this? Maybe the round function is not the way to >go. I'm a newbe. What other function will work for this. Fuzz? > >Terry >_____________________________ >Terry J. Kohls >Lab Technician >VPI, LLC >tjkohls@vpicorp.com > ><< msg2.html >>

--------------------------------------- Dale McLerran Fred Hutchinson Cancer Research Center mailto: dmclerra@fhcrc.org Ph: (206) 667-2926 Fax: (206) 667-5977 ---------------------------------------

------------------------------------------------------------ --== Sent via Deja.com ==-- http://www.deja.com/


Back to: Top of message | Previous page | Main SAS-L page