Date: Mon, 27 Sep 2010 17:24:26 -0400
Reply-To: Nat Wooding <nathani@VERIZON.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nat Wooding <nathani@VERIZON.NET>
Subject: Re: by group processing, sas certification book, 2nd ed
In-Reply-To: <B282BE35B5A4494894D4ECFBA2BF7847180B6C0A88@XCH-NW-17V.nw.nos.boeing.com>
Content-Type: text/plain; charset="us-ascii"
I have not followed this thread closely but the following table from the
Concepts section of the documentation may help. I inserted the table as HTML
and I hope that it will be legible to all.
Nat Wooding
Grouping Observations by State, City, Zip Code, and Street
This example shows how SAS uses the FIRST.variable and LAST.variable to flag
the beginning and end of four BY groups: State, City, ZipCode, and Street.
Six temporary variables are created within the program data vector. These
variables can be used during the DATA step, but they do not become variables
in the new data set.
In the figure that follows, observations in the SAS data set are arranged in
an order that can be used with this BY statement:
by State City ZipCode;
SAS creates the following temporary variables: FIRST.State, LAST.State,
FIRST.City, LAST.City, FIRST.ZipCode, and LAST.ZipCode.
Observations in Four BY Groups
Corresponding FIRST. and LAST. Values
State
City
ZipCode
Street
FIRST. State
LAST. State
FIRST. City
LAST. City
FIRST. ZipCode
LAST. ZipCode
AZ
Tucson
85730
Glen Pl
1
1
1
1
1
1
FL
Miami
33133
Rice St
1
0
1
0
1
0
FL
Miami
33133
Tom Ave
0
0
0
0
0
0
FL
Miami
33133
Surrey Dr
0
0
0
0
0
1
FL
Miami
33146
Nervia St
0
0
0
0
1
0
FL
Miami
33146
Corsica St
0
1
0
1
0
1
OH
Miami
45056
Myrtle St
1
1
1
1
1
1
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Schwarz, Barry A
Sent: Monday, September 27, 2010 3:20 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: by group processing, sas certification book, 2nd ed
The number of variables in an observation has no affect on the first. and
last. variables. Did you mean three or more observations?
Consider a data set with one character variable named x
obs x
1 a
2 b
3 b
4 c
5 c
6 c
Processing this data set with SET and BY x will result in
obs first.x last.x
1 1 1
2 1 0
3 0 1
4 1 0
5 0 0
6 0 1
If this doesn't address the area of your confusion or if you think the
results should be different, your question needs to be more specific.
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
bbser2009
Sent: Saturday, September 25, 2010 12:17 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: by group processing, sas certification book, 2nd ed
Hi there,
I have read the portion about by group processing in Chapter 12 several
times, still feel confused about those examples presented (I even think they
make mistakes), about the first.variable and last.variable in the situation
where we have 3 or more by variables.
Anyone, by any chance, has read that book? Is there better source explaining
by group processing, first and last.variables?