1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
*Want to select cases where spellnr=3 as well as the preceding and following case of the same person.
* Posted to SPSSX-L by Raynald Levesque on 2002/11/22.

DATA LIST LIST /Persnr    Spellnr spelltyp   begin end  sex.
BEGIN DATA
203        1         2        143  144   1
203        2         2        145  199   1
203        3         3        199  204   1
605        1         1        155  156   2
605        2         4        157  167   2
605        3         3        168  180   2
605        4         1        181  190   2
702        1         3        167  204   2
END DATA.
LIST.

COMPUTE casen=$CASENUM.
COMPUTE tz=(spelltyp=3).
IF LAG(tz)=1 & Persnr=LAG(Persnr) after=1.

SORT CASES BY casen(D).
IF LAG(tz)=1 & Persnr=LAG(Persnr) before=1.
SORT CASES BY casen(A).
COMPUTE flag=MIN(1,SUM(tz,after,before)).
EXECUTE.
SELECT IF flag=1.
EXECUTE.