```Date: Sun, 9 May 1999 14:51:16 -0400 Reply-To: Dave Steven Sender: "SAS(r) Discussion" From: Dave Steven Subject: Re: Number Problems In-Reply-To: <372E557C.B039D231@mediaone.net> Content-Type: TEXT/PLAIN; charset=US-ASCII As Robert Virgile notes, this is a digital computer thing, the results having to do with the precision of your computer, and not with SAS... The operation you're attempting is a real number subtraction (as opposed to integer); the result is an approximation. Look up the FUZZ function in your SAS Language Reference. FUZZ can be used to accept two values as equal if they are within 1E-12 of each other (adds some computational slack to offset the real number approximation). I don't know what your specific goal is, but I hope this helps... -Dave * * * * * * * * Dave Steven, Senior Research Programmer * * http://cac.psu.edu/~dcsteven/ * Penn State * * * Graduate Education and Research Services, NIC Group * 1 8 5 5 * The Center for Academic Computing * * --------------------------------------------------- * * 214F Computer Bldg 814-865-0980 dcsteven@psu.edu * University Park, PA 16802 FAX: 814-863-7049 Those who do not understand Unix are condemned to reinvent it, poorly. -- Henry Spencer On Mon, 3 May 1999, Robert Virgile wrote: >Not elegant, but possibly a way to work around the problem. (Yes, computers will >probably always have this type of problem in one form or another.) > >You could try multiplying all your numbers by 10000 to get integers. Perform the >subtraction and then (if necessary), divide by 10000. Like I said, not very >elegant, but you won't have any of these rounding/truncating problems with integer >arithmetic. > > > >Schmeidd wrote: > >>I am having a problem subtracting two numbers on the mainframe. For example, I >>have two numbers, 213.8013 and 213.8010, and subtract the second from the >>first. The answer one would expect is .0003. The answer I get is >>.00029999999642. (Again, these numbers are just examples.) >> >>I have tried many ways to get around this problem, the FLOOR and CEILING >>functions, rounding, multiplying by a high exponent of 10 and trying to >>manipulate the number that way, turning the number into a character and >>truncating, to name a few. I have also applied a format with 20 decimal places >>to see what I was dealing with. The number contained zeros to the 20th decimal >>place. >> >>This does not happen on the PC. It was explained to me in brief as something >>caused by the way the mainframe handles numbers, and number theory. >> >>Has anyone encountered this before? And does anyone have a solution to this >>problem? I have called the SAS Institute and they cannot shed any light on >>this problem. >> >>Thanks in advance for any help. >> >>David Schmeidler >>Dyncorp >>schmeidd@dyncorp.com ```

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