|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?|
|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=;
If this is the case, then you need to use the round function in your if
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.
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Roger
Sent: Friday, September 03, 2004 11:03 AM
Subject: Re: SAS Bug - IF-ELSE?
Could you show us some inputs and outputs?
> 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!
> DATA D2;
> SET D1;
> IF DUM=0 THEN DO;
> IF X1=0.0625 THEN PRE=1; ELSE PRE=0;
> IF DUM=1 THEN DO;
> IF X1=0.01 THEN POST=1; ELSE POST=0; /*SECOND IF-ELSE STATEMENT*/
> END; RUN;