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
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
SPSS AnswerNet: Result 

Solution ID:	 	100000681	
Product:	 	SPSS Base 	

Title:
Mixed File With No Record Identifier 
Description:
Q. 
I have a file which is basically a mixed file 
type, but I don't have any field which identifies 
what type of record is on a given line of data. 
I was, however, keen enough to put a code which 
indicates when a new case is starting. Is there 
any way I can get SPSS to read the data? 
A. 
Yes, there is. Study the following program and 
modify it to fit your problem. Here are some 
points to consider: 
Most importantly: The file does not have any record type information 
coded in the data. Such information has to be inferred by the following 
information: 
(A) There is a means of detecting that a new case is starting 
(/// in first 3 columns). 
(B) There is a constant number of initial records (One in this 
case, it is easy to modify the program to permit more) 
(C) There are one or more lower level records each with 
the same structure. If there is more than one type of 
lower level record the person is out of luck. 
********************************************************************. 
* This input program will read the following form of complex file * 
* A new case begins with a flag (in this case ///). * 
* The first record is a header record describing the observation * 
* Unit. Following that is an unknown number of records of a given * 
* type (in this case consisting of 3 variables). The goal is to * 
* construct a single record containing all variables for each case * 
********************************************************************. 
INPUT PROGRAM. 
NUMERIC ID. 
VECTOR DATA(30). 
DATA LIST /#S 1-3 (A). /************************/ 
DO IF (#S = '///'). /* New subject begins */ 
+ COMPUTE #COUNT=0. /* Initialize Counter */ 
+ DATA LIST /ID 1-3 H1 TO H10 5-24. /* Read header record */ 
+ ELSE. /* Either H or M record */ 
+ COMPUTE #COUNT = #COUNT+1. /* Increment Counter */ 
+ LEAVE ID H1 TO H10. /* Carry Header Info */ 
+ REREAD. /************************/ 
+ DATA LIST /#M1 TO #M3 1-12. /* Read an M Record */ 
+ VECTOR #M= #M1 TO #M3. /* Utilize vectors and */ 
+ Compute #Offset = (#COUNT-1)*3. /* Loop to Distribute */ 
+ LOOP #X=1 to 3. /* The record into the */ 
+ COMPUTE DATA(#Offset +#X) = #M(#X). /* Correct Locations */ 
+ END LOOP. /************************/ 
END IF. 
END INPUT PROGRAM. 
BEGIN DATA. 
/// 
001 11121314151617181910 
111 112 113 
121 122 123 
131 132 133 
141 142 143 
151 152 153 
161 162 163 
/// 
002 21222324252627282920 
211 212 213 
221 222 223 
231 232 233 
241 242 243 
/// 
003 31323334353637383930 
311 312 313 
321 322 323 
331 332 333 
341 342 343 
351 352 353 
361 362 363 
371 372 373 
381 382 383 
391 392 393 
301 302 303 
END DATA. 
SELECT IF (NOT (SYSMIS(ID))). 
AGGREGATE OUTFILE= * 
/ BREAK = ID 
/ HEADER1 TO HEADER10 = FIRST(H1 TO H10) 
/ DATA1 TO DATA30 = MAX ( DATA1 TO DATA30). 
FORMATS ALL (F3.0). 
LIST. 

THE VARIABLES ARE LISTED IN THE FOLLOWING ORDER: 
LINE 1: ID HEADER1 HEADER2 HEADER3 HEADER4 HEADER5 HEADER6 HEADER7 HEADER8 
HEADER9 HEADER10 DATA1 DATA2 DATA3 DATA4 DATA5 DATA6 
LINE 2: DATA7 DATA8 DATA9 DATA10 DATA11 DATA12 DATA13 DATA14 DATA15 DATA16 
DATA17 DATA18 DATA19 DATA20 DATA21 DATA22 DATA23 
LINE 3: DATA24 DATA25 DATA26 DATA27 DATA28 DATA29 DATA30 
ID: 1 11 12 13 14 15 16 17 18 19 10 111 112 113 121 122 123 
DATA7: 131 132 133 141 142 143 151 152 153 161 162 163 . . . . . 
DATA24: . . . . . . . 
ID: 2 21 22 23 24 25 26 27 28 29 20 211 212 213 221 222 223 
DATA7: 231 232 233 241 242 243 . . . . . . . . . . . 
DATA24: . . . . . . . 
ID: 3 31 32 33 34 35 36 37 38 39 30 311 312 313 321 322 323 
DATA7: 331 332 333 341 342 343 351 352 353 361 362 363 371 372 373 381 382 
DATA24: 383 391 392 393 301 302 303 
Number of cases read: 3 Number of cases listed: 3