Read a variable number of records per case
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | I have a text file generated by an old, no-longer-used data entry program (KE3). Each case has multiple records, and the number of records varies from case to case. Each record contains a response to a question; some of the responses exceed 80 characters (limitation of KE3) and so are continued on another line. I'd like to import these data into SPSS, combining related records. For each line, columns 1 - 3 contain the "card number" -- which corresponds to a specific item in the survey. (The reference to "cards" indicates the age of the program these data were entered in...) Columns 4-6 contain the family ID number; column 7 is a "person ID number", columns 8 - 91 contain the response for the item. So, cards 400 through 477 are a single case. You will see that the cases each have a different number of records -- when an answer exceeds the 91-column limit, it is continued on the next line(s), with the *same* card number. For example, in the first case, card 447 is entered twice to accommodate a longer answer. In the second case, card 406 is entered four times to accommodate an even longer answer. *(A) Posted to SPSSX-L by Ray on 2002/08/17. * Syntax assumes that the maximum length of a response is 255 characters. DATA LIST FIXED /cardnb 1-3(F) familyid 4-6 (F) personid 7-7 (F) response 8-91(A). BEGIN DATA 40005431SHORT ANSWER 4010543SHORT ANSWER 40205438 40305438 40405438 40505438 40605438 40705438 40805438 40905438 41005438 41105438 41205438 41305438 41405438 4150543SHORT ANSWER 4160543SLIGHTLY LONGER ANSWER 41705438 41805438 41905438 42005438 42105438 42205438 42305438 42405438 42505438 42605438 42705439 42805438SHORT ANSWER 42905438 43005438 43105438 43205438 43305438 43405438 43505438 43605438 43705438 4380543 SHORT ANSWER 4390543 SHORT ANSWER 44005438 44105438 44205438 44305438 44405438 44505438 44605438 4470543LONG ANSWER THAT IS CONTINUED ACROSS TWO LINES 4470543REST OF LONG ANSWER THAT IS CONTINUED ACROSS TWO LINES 4480543 SHORT ANSWER 4490543 SHORT ANSWER 45005438 45105438 45205438 45305438 45405438 45505438 45605438 45705438 45805438 45905438 46005438 46105438 4620543 SHORT ANSWER 46305438 46405438 46505438 46605438 4670543 SHORT ANSWER 46805438 4690543 SHORT ANSWER 47005438 47105438 47205438 47305438 47405438 47505438 47605438 47705438 4003013 SHORT ANSWER 4013013 40230138 40330138 40430138 40530138 4063013LONG ANSWER THAT GOES ON AND ON 4063013LONG ANSWER THAT GOES ON AND ON 4063013LONG ANSWER THAT GOES ON AND ON 4063013LONG ANSWER THAT GOES ON AND ON 40730138 40830138 40930138 41030138 41130138 41230138 41330138 41430138 41530134063013LONG ANSWER THAT GOES ON AND ON 41530134063013LONG ANSWER THAT GOES ON AND ON 41530134063013LONG ANSWER THAT GOES ON AND ON 4163013SHORT ANSWER 41730138 41830138 41930138 42030138 42130138 42230138 42330138 42430138 42530138 42630138 4273013SHORT ANSWER 4283013 SHORT ANSWER 42930138 43030138 43130138 4323013 SHORT ANSWER 43330138 43430138 43530138 43630138 43730138 4383013 SHORT ANSWER 4393013 SHORT ANSWER 44030138 44130138 44230138 44330138 44430138 44530138 44630138 4473013 SHORT ANSWER 44830138 44930138 4503013 SHORT ANSWER 4513013 SHORT ANSWER 4523013 4533013 45430138 45530138 45630138 45730138 4583013 4593013 4603013 4613013 4623013 4633013 4643013 4653013 4663013 4673013 46830138 4693013 4703013 SHORT ANSWER 4713013 4723013 47330138 47430138 47530138 47630138 4773013 40039331 4013933 40239338 40339338 40439338 40539338 40639338 40739338 40839338 40939338 41039338 41139338 41239338 41339338 41439338 4153933 SHORT ANSWER 4163933 41739338 41839338 41939338 42039338 42139338 42239338 42339338 42439338 42539338 42639338 42739339 42839338 42939338 4303933 SHORT ANSWER 43139338 43239338 43339338 43439338 43539338 43639338 43739338 43839338 43939338 44039338 44139338 44239338 44339338 44439338 44539338 44639338 4473933LONG ANSWER THAT GOES ON AND ON 4473933LONG ANSWER THAT GOES ON AND ON 4473933LONG ANSWER THAT GOES ON AND ON 4473933LONG ANSWER THAT GOES ON AND ON 4473933LONG ANSWER THAT GOES ON AND ON 4473933LONG ANSWER THAT GOES ON AND ON 44839338 44939338 45039338 45139338 45239338 45339338 45439338 45539338 45639338 45739338 4583933 45939338 46039338 46139338 46239338 46339338 46439338 46539338 4663933 46739338 46839338 46939338 47039338 47139338 47239338 47339338 47439338 47539338 47639338 47739338 40019431SHORT ANSWER 4011943 SHORT ANSWER 40219438 40319438 40419438 4051943 SHORT ANSWER 40619438 40719438 40819438 40919438 41019438 41119438 41219438 4131943 SHORT ANSWER 41419438 4151943 SHORT ANSWER 4161943 SHORT ANSWER 41719438 41819438 41919438 42019438 42119438 42219438 42319438 42419438 42519438 42619438 42719439 42819438 42919438 4301943 SHORT ANSWER 43119438 43219438 43319438 43419438 43519438 43619438 43719438 4381943 SHORT ANSWER 4391943 SHORT ANSWER 44019438 44119438 44219438 44319438 44419438 44519438 44619438 4471943 SHORT ANSWER 44819438 44919438 4501943 SHORT ANSWER 4511943 SHORT ANSWER 45219438 45319438 45419438 45519438 45619438 45719438 458194 SHORT ANSWER 45919438 46019438 46119438 46219438 46319438 46419438 46519438 46619438 46719438 46819438 46919438 47019438 47119438 47219438 47319438 47419438 47519438 47619438 47719438 END DATA. LIST /CASES=FROM 1 TO 25. SORT CASES BY familyid personid cardnb. COMPUTE casen=$CASENUM. RANK VARIABLES=casen BY familyid personid cardnb /RANK INTO respnb. STRING totresp(A255). COMPUTE totresp=response. IF respnb >1 totresp=CONCAT(RTRIM(LAG(totresp)),LTRIM(response)). MATCH FILES FILE* /BY=familyid personid cardnb /LAST=last /DROP=respnb. SELECT IF last=1. STRING card400 TO card477(A255). VECTOR card=card400 TO card477. COMPUTE card(cardnb-399)=totresp. AGGREGATE OUTFILE=* /PRESORTED /BREAK=familyid personid /card400 TO card477 = MAX(card400 TO card477). * Make data window easy to read. DO REPEAT var=ALL. VARIABLE WIDTH var(11). END REPEAT. EXECUTE. |
Related pages
...