great solution, Dan
I was about to type: ceiling and floor to do something similar.
todo: does sum(0.01,0.99) equal $1.00?
Ron Fehd $0.02 worth
> -----Original Message-----
> From: firstname.lastname@example.org [mailto:owner-sas-
> email@example.com] On Behalf Of Nordlund, Dan (DSHS/RDA)
> Sent: Monday, August 22, 2011 2:57 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: RE: An issue with precision?
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> > Kroll, J. (Jeffrey)
> > Sent: Monday, August 22, 2011 10:39 AM
> > To: SAS-L@LISTSERV.UGA.EDU
> > Subject: Re: An issue with precision?
> > Ok, this precision thing is kickin my butt.
> > Again, let me recap what Im trying to do. Im reading in a file that
> > has
> > a key and several money values that are stored as packed decimal
> > values.
> > One of the money fields has a value of 1439.62. Its stored as
> > '000000000143962C'x. Im reading the value as PD8.2 Proc Print
> > without any formats shows the value as 1439.62. Wonderful. However,
> > in
> > trying to resolve this issue Id thought Id multiply the number by
> > so I could work with integers only. Anyway, printing out that number
> > got me 14396199. Sheesh, even my calculator can get that one right.
> > So
> > I figure I can work with this. Later in the process I need to take
> > this
> > record and split it into two and apply a factor to each record. The
> > factors for this record are .01 and .99. I need to do something
> > similar for the whole file(approx 450k records). What I want to be
> > able
> > to do when Im done is total up the column with the new factored
> > and come very close to what the total of the unfactored numbers would
> > be. Make sense? If only it were that easy. Several of you have
> > nice enough to recommend the FUZZ function. Im not sure how that
> > help me. The overall variance is a shade over $213,000 but that
> > to less than .01% of the total. Still, I would like to get closer.
> > Anyone have any advice? Thanks.
> Welcome to the wonderful world of floating-point calculations. First,
> You should use PD8.0 to read in your data (i.e. work in pennies). Then
> when you "split" the record into two, multiply by one factor, say .01,
> then round, then subtract to get the other "half". At the end you can
> convert to dollars and cents for reporting.
> Value = 143962;
> V01= round(value*0.01);
> V99 = value - v01;
> Whether this is acceptable or not depends on your business rules, of
> which I have no clue. (For example, does it make sense for an
> individual record to have fractional cents?) However, it should
> produce totals that match exactly.
> Hope this is helpful,
> Daniel J. Nordlund
> Washington State Department of Social and Health Services
> Planning, Performance, and Accountability
> Research and Data Analysis Division
> Olympia, WA 98504-5204