Date: Tue, 23 Sep 2003 16:21:04 -0400
Reply-To: Venky Chakravarthy <venky.chakravarthy@PFIZER.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Venky Chakravarthy <venky.chakravarthy@PFIZER.COM>
Subject: Re: FIRST. and LAST. processing and the WHERE statement
On Mon, 22 Sep 2003 14:52:25 -0500, Greg Woolridge <greg.woolridge@TAP.COM>
wrote:
>From what I can see in the SAS documentation, when a BY statement is used
>the special variables FIRST. and LAST. are set when an observation is read
>into the PDV. The WHERE statement affects whether or not an observation is
>read into the PDV. Based on this I think that the WHERE statement could
>affect which observation from an input data set is designated as FIRST.
>For instance, if a BY group has 5 observations in the input data set, but
>the first 2 do not meet the WHERE clause condition (i.e. they are not read
>into the PDV) then the third observation would be designated as FIRST. Am
>I correct in my assumptions, or am I missing something?
>
>Greg M. Woolridge
>Manager, Study Programming
>TAP Pharmaceutical Products Inc.
>e-mail: greg.woolridge@tap.com
>phone: 847-582-2332
>fax: 847-582-2403
A while ago, when I was testing something with the debugger on, I noticed
that the first.var and the last.var are set to 1 before a single
observation is even read in. Most likely this is a compile time activity.
You can see this by writing out the two variables to the log before the
first observation is read. I have deliberately output a data set with 0
observations.
47 data q ;
48 x = 1 ;
49 stop ;
50 run ;
NOTE: The data set WORK.Q has 0 observations and 1 variables.
NOTE: DATA statement used:
real time 0.01 seconds
cpu time 0.00 seconds
51
52 data w ;
53 put first.x= last.x= ;
54 set q ;
55 by x ;
56 run ;
first.x=1 last.x=1
Kind Regards,
Venky
|