```Date: Tue, 20 Dec 2005 08:37:21 -0800 Reply-To: "Terjeson, Mark (IM&R)" Sender: "SAS(r) Discussion" From: "Terjeson, Mark (IM&R)" Subject: Re: Numeric Precision Problem Comments: To: Ed Heaton Content-Type: text/plain; charset="us-ascii" Thanks Ed for elaborating! :o) Appreciate you taking the time. -----Original Message----- From: Ed Heaton [mailto:EdHeaton@westat.com] Sent: Tuesday, December 20, 2005 8:31 AM To: Terjeson, Mark (IM&R); SAS-L@LISTSERV.UGA.EDU Subject: RE: Re: Numeric Precision Problem Mark; Consider the following code. Data _null_ ; Do i=0 by 0.01 until ( i eq 0.1 ) ; Put i= binary64. ; End ; Run ; This would loop only 11 times if SAS could accurately store 0.01 and 0.1. However, SAS can't. Let's look at the was SAS stores 0.1 ... 1 Data _null_ ; 2 x = 0.1 ; 3 Put x= binary64. ; 4 Run ; x=0011111110111001100110011001100110011001100110011001100110011010 Now, the first byte is the sign (0 means positive), the next 11 bits represent the exponent and the remainder of the bits represent the decimal part of the mantissa. The integer part of the mantissa is always 1 and is not stored. Look at the mantissa. It is a repeating pattern of 1001. In fact, if you were to store 0.1 accurately in this binary format, the repeating pattern of 1001 would never end. That is much the same as 1/3 expressed in decimal creates a repeating pattern that never ends. So, SAS can't store 0.1 accurately. Ed Edward Heaton, SAS Senior Systems Analyst, Westat (An Employee-Owned Research Corporation), 1600 Research Boulevard, RW-4541, Rockville, MD 20850-3195 Voice: (301) 610-4818 Fax: (301) 294-3879 mailto:EdHeaton@Westat.com http://www.Westat.com ```

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