Date: Fri, 31 Mar 2006 21:59:42 -0800
Reply-To: Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Subject: Re: Q: Evaluation of conditional expressions
In-Reply-To: <BAY101-F3538B5FA55A0D5F9A381E6DED60@phx.gbl>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
I don't know the answer to your question, but I will say that coding
options nocodegen;
before the original test code will produce interesting results.
on 3/30/2006 9:49 PM toby dunn said the following:
> Howard ,
>
> A timely and wise post as ussual. I actually came across this earlier
> today
> when i was trying to get the note "created missing values at" out of my
> log.
> I didnt have a whole lot of time to reflect upon this then but now I do.
> It seem logical that a lag in the if condition would need to be executed
> every time so the queue will be filled properly.
>
> So is it the case that the If condition will have to compare all arguments
> before determining if it is false or true or is it the case where it is
> smart enough and only does a full comparison if there is such things like
> the lag function which need to be executed every time to work properly?
>
> Since you have proven one half wonder how one would prove the other?
>
>
>
> Toby Dunn
>
>
>
>
>
> From: "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
> Reply-To: "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: Q: Evaluation of conditional expressions
> Date: Thu, 30 Mar 2006 21:56:58 -0500
>
> Here's a counterexample.
>
> data _null;
> do x = 1 to 10;
> if mod(x,2)=1 and lag(x)=x-1 then put x=;
> end;
> run;
>
> It produces:
>
> x=3
> x=5
> x=7
> x=9
>
> If the condition following the AND were bypassed for the even values of X,
> then the LAG function could not return those even values during the odd-X
> iterations.
>
> That's a good thing. On the odd-X iterations, the result returned by LAG
> isn't needed, but the side effect (storing the current X so that it can be
> returned by the *next* call) is important.
>
> Perhaps SAS is smart enough to optimize around evaluation of moot
> conditions, but to make exceptions when side effects are important.
>
> On Mon, 27 Mar 2006 14:25:09 +0000, toby dunn <tobydunn@HOTMAIL.COM> wrote:
>
> >Jim ,
> >
> >With any 'AND' condition if the first part is not true SAS will not go on
> >and check the second part since the logic dictates that both parts
> have to
> >be true.
> >
> >
> >
> >Toby Dunn
> >
> >
> >
> >
> >
> >From: Jim Groeneveld <jim2stat@YAHOO.CO.UK>
> >Reply-To: Jim Groeneveld <jim2stat@YAHOO.CO.UK>
> >To: SAS-L@LISTSERV.UGA.EDU
> >Subject: Q: Evaluation of conditional expressions
> >Date: Mon, 27 Mar 2006 03:20:15 -0500
> >
> >Hi friends,
> >
> >Suppose x = 1 and y = 2, then what would the conditional expression
> >IF (X EQ 0 AND Y EQ 0)
> >in a data step do? X is not 0, the evaluation of the first part yields
> >false, so the whole condition is not true, but is the condition Y EQ 0
> >evaluated as well? It is my impression it is not, but I am not sure.
> Where
> >can I find this in the docs?
> >
> >Regards - Jim.
> >--
> >Jim Groeneveld, Netherlands
> >Statistician, SAS consultant
> >home.hccnet.nl/jim.groeneveld
>
|