Date: Tue, 23 Aug 2011 20:18:38 -0400
Reply-To: Jay Smith <twainpeare@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jay Smith <twainpeare@GMAIL.COM>
Subject: Get 2 records before and records after
Dear all,
Suppose you have a dataset that might look like:
DATA temp;
INPUT name x rank;
DATALINES;
ABC123 34 1
CDF234 14 2
FEG343 19 3
EGE473 27 4
GAS308 52 5
PIE343 11 6
MYD987 34 7
COL138 40 8
HAK989 47 9
FRF879 35 10
;
RUN;
I'd like to identify a set of "groups" associated with each record. The rule
is that the groups are made up of the 2 records below it and the 2 records
above it (data is already sorted appropriately by rank) So for example,
PIE343belongs in a group with MYD987, COL138, GAS308, and EGE473. Upon
identifying those groups members, I would like to add them to the dataset
for that record so the PIE343 record would look something like:
(name) (x) (rank) (group1) (group2) (group3) (group4)
PIE343 11 6 EGE473 GAS308 MYD987 COL138
Any help would be greatly appreciated. Many thanks in advance.
-J
|