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 (September 1998, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 24 Sep 1998 12:34:19 -0700
Reply-To:     "Berryhill, Timothy" <TWB2@PGE.COM>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         "Berryhill, Timothy" <TWB2@PGE.COM>
Subject:      Re: Numeric precision problem
Content-Type: text/plain

As was pointed out in a previous message, there is NO general solution to this problem. In general, if you try to select or exclude numbers using exact values, you will occasionally be disappointed. Consider the short program:

6 data _null_; 7 one=(1/3)*3; 8 zero=1-one; 9 put one= zero=; 10 if one eq 1 then put 'OK'; else put 'Oops'; 11 run;

ONE=1 ZERO=1.387779E-17 OOPS

Although SAS displays the variable ONE as having a value of 1, it is in fact slightly less than 1. Line 7 calculated 1/3 as 0.333333333, then multiplied it by 3 and got 0.9999999, which displays as 1 but is really a little less. Using EQ in character comparisons is fine, but in numeric comparisons it will fail.

> ---------- > My "generic" solution has been to define an array over all _numeric_ > variables, and > then round all elements of the array to a specified decimal place (e.g. > .000001) which > is appropriate for all the data included in the given dataset. My code > looks like: > > data newfile; > set downloaded_file; > array _num (*) _numeric_; > do _i=1 to dim(_num); > _num(_i)=round(_num(_i),.000001); > end; > drop _i; > run; > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > Date: Thu, 24 Sep 1998 05:10:21 -0700 > From: Lei Yao <lei_yao@YAHOO.COM> > Subject: Re: Numeric precision problem > > Thanks for all the response to my numeric precision problem. It works > fine while using ROUND function. Another question is: Are there any > general ways to fix this problem? It will be a lot of work if you > have many data sets with many numeric variables like this. >


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