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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
*(Q) I am trying to read an ASCII file that contains anywhere from 4 to 11
records.  The first 4 records contain data, while the final 7, if they
exist, contain text ("other, specify" responses to a questionnaire).  While
the number of records per case varies, each record begins with the CASEID
(something like this)....

0000001 1 2 3 12 13 12
0000001 2 2 3 09 08 01
0000001 1 1 2 06 14 22
0000001 1 4 7 09
0000002 1 2 3 01 10 11
0000002 3 1 2 01 09 02
0000002 1 1 3 07 15 20
0000002 1 2 1 12
0000002 text1
0000002 text2
0000002 text3
0000002 text4

*(A) Posted to SPSSX-L on 2001/11/06 by rlevesque@videotron.ca.
* http://pages.infinit.net/rlevesqu/index.htm.


NEW FILE.
INPUT PROGRAM.
STRING mytext(A40).
* read data line assuming it does not contain text.
DATA LIST LIST /id ans1 TO ans6.

DO IF MISSING(ans1) & (id=LAG(id)).
* Oopps it contains text: reread data line.
REREAD.
DATA LIST LIST /id mytext.
END IF.

END CASE.
END INPUT PROGRAM.

BEGIN DATA
0000001 1 2 3 12 13 12
0000001 2 2 3 09 08 01
0000001 1 1 2 06 14 22
0000001 1 4 7 09
0000002 1 2 3 01 10 11
0000002 3 1 2 01 09 02
0000002 1 1 3 07 15 20
0000002 1 2 1 12
0000002 text1
0000002 text2
0000002 text3
0000002 text4
END DATA.


LIST.
COMPUTE casenb=$CASENUM.
RANK  VARIABLES=casenb BY id  /RANK INTO recno.

VECTOR text(4A40) /ans=ans1 TO ans6 /answ(24F8.0).
DO IF recno<5.
LOOP cnt=1 TO 6.
COMPUTE #idx=cnt + (recno-1) * 6.
COMPUTE answ(#idx)=ans(cnt).
END LOOP.
ELSE.
COMPUTE text(recno - 4)=mytext.
END IF.
EXECUTE.

AGGREGATE
  /OUTFILE=*
  /BREAK=id
  /answ1 TO answ22= FIRST(answ1 TO answ22) /text1 TO text4 = MAX(text1 TO text4).