Date: Wed, 2 Jul 2008 12:35:13 +0200
Reply-To: Marta García-Granero <mgarciagranero@gmail.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Marta García-Granero <mgarciagranero@gmail.com>
Subject: Re: selecting cases???????
In-Reply-To: <DB513A51-BAA6-4173-895D-25DE25FAE7AD@mimectl>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hi Samuel
> All I need to delete is cases 'D' and 'E' and hence the sequence
> (2003,2004,2005,2003,2004,2005,..........it goes like that) is kept
> intact. You were wondering if the range is between 2003 and 2005.
> well that is right. there are only 2003,2004 and 2005. I just need to
> keep the sequence and delete the rest which are in between that does
> follow the order.
>
I have added some cases to your sample dataset just to be ready to deal
with other "out of sequence" data, like 2003 followed by 2005 (see ID
"O" & "P"), besides the case you presented (2004 without a 2003 before,
like in ID "D" & "E").
* Sample dataset *.
DATA LIST LIST/ID(A1) year(F8).
BEGIN DATA
A 2003
B 2004
C 2005
D 2004
E 2005
F 2003
G 2004
H 2005
I 2003
J 2004
K 2005
L 2003
M 2004
N 2005
O 2003
P 2005
END DATA.
NUMERIC Flag(F8).
COMPUTE Flag=(year=2003).
* This part flags sequences not starting with 2003 *.
DO IF Flag NE 1.
- IF (year=2004) AND (LAG(year,1)=2003) Flag=1.
- IF (year=2005) AND (LAG(year,2)=2003) Flag=1.
END IF.
* This part flags sequences starting with 2003 not followed by 2004 *.
SORT CASES BY ID(D).
IF (year=2003) AND (LAG(year) NE 2004) Flag=0.
* Now we get rid of every flag=0 data *.
EXE. /*don't eliminate it *.
SELECT IF Flag=1.
SORT CASES BY ID(A).
DELETE VARIABLES Flag.
LIST.
HTH,
Marta García-Granero
=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
|