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 2004, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 3 Sep 2004 17:40:40 -0400
Reply-To:   Don Henderson <DonaldJHenderson@HOTMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Don Henderson <DonaldJHenderson@HOTMAIL.COM>
Subject:   Re: SAS Bug - IF-ELSE?
In-Reply-To:   <41388731.3040905@verizon.net>
Content-Type:   text/plain; charset="us-ascii"

A fairly likely possibility is that if X1 is a calculated field that its value is not really .01, but prints as .01. Remember that many decimal values can not be stored precisely (there have been many threads in the past on this topic). So for example, if X1 is .00999999995, The if will not be satisfied, but the value of X1 might appear to be .01 as can be seen by:

59 data _null_; 60 x1 = .00999999995; 61 put x1=; 62 run;

x1=0.01

If this is the case, then you need to use the round function in your if statement, e.g.:

If round(x1,.01) = .01 . . . .

Note that the .01 in the round function is not the value you are comparing to - it is the level of precision - in this case two digits to the right of the decimal point.

HTH, -don h.

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Roger Lustig Sent: Friday, September 03, 2004 11:03 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: SAS Bug - IF-ELSE?

Thomas: Could you show us some inputs and outputs?

Thanks,

Roger

Thomas wrote: > Hi all, > > I tried to do a very simple IF-ELSE statement in SAS, but I encounted > a weird problem that SAS cannot recognize the second IF-ELSE statement > in the second DO-END statement. However, the first DO-END statement > has no problem that SAS returned the correct output for X1=0.0625. X1 > here is numeric. I am wondering why SAS can recognize first DO-END > statement with X1=0.0625 condition, but cannot recognize the second > DO-END statement with X1=0.01 IF-ELSE condition. > I would very much appreciate it, if anyone could kindly help me. > > Thank you very much! > Thomas > > > DATA D2; > SET D1; > > IF DUM=0 THEN DO; > IF X1=0.0625 THEN PRE=1; ELSE PRE=0; > END; > > IF DUM=1 THEN DO; > IF X1=0.01 THEN POST=1; ELSE POST=0; /*SECOND IF-ELSE STATEMENT*/ > END; RUN;


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