UCLA Academic Technology Services HomeServicesClassesContactJobs

SPSS Code Fragments
Reading a multiple-line-per-subject data file

SPSS will read datasets with multiple lines per subject. The method used below requires that the data be in fixed format. The command records gives the number of lines of data per subject. The /1 and /2 list the variables and their position on the respective lines of data.

* two lines of data per subject .
data list records=2
/1 a 1 b 3 c 5
/2 d 1 e 3 f 5 .
begin data .
1 2 3
4 5 6
1 3 5
2 4 6
end data .

list .


Data List will read 2 records from the command file

Variable          Rec   Start     End  Format
a                   1       1       1  F1.0
b                   1       3       3  F1.0
c                   1       5       5  F1.0
d                   2       1       1  F1.0
e                   2       3       3  F1.0
f                   2       5       5  F1.0

List

a b c d e f

1 2 3 4 5 6
1 3 5 2 4 6

Number of cases read:  2    Number of cases listed:  2

* three lines of data per subject .
data list records=3
/ a 1 b 3
/ c 1 d 3
/ e 1 f 3  .
begin data .
1 2
3 4
5 6
1 3
5 2
4 6
9 8
7 6
5 4
end data.
list .


Data List will read 3 records from the command file

Variable          Rec   Start     End  Format
a                   1       1       1  F1.0
b                   1       3       3  F1.0
c                   2       1       1  F1.0
d                   2       3       3  F1.0
e                   3       1       1  F1.0
f                   3       3       3  F1.0

List

a b c d e f

1 2 3 4 5 6
1 3 5 2 4 6
9 8 7 6 5 4

Number of cases read:  3    Number of cases listed:  3

* example reading in a file;
* this example assumes that you have saved this data set as a text file in "d:/data/multiple-line.txt";
* note v3 is missing for case 2 .

100010133346851              1 1330              7954140200                 5069
1000102           201  7                         *    2 2 2  *  4  4  8 8 8    john
1000103            5-              -                                   533
1000104            59                2                                 633
1000105            5-              -                                   522
1000106            222222222222
1000107            34
1000108            2336
1000109            2336
1000110            2555
1000111            400                                                         2
100020113226652      1       1 1340              7952140200                 5069
1000202           101  7                         *    *      *  *  6  * 7 7    carl
1000203            2  1         4             2  1                    431401
1000204            2  1         4             2  1                    432404
1000205            5-                3                                 622
1000206            543343442243
1000207            44
1000208            122
1000209            1223
1000210            2555
1000211            260   

data list file="d:/data/multiple-line.txt" records=11
/1 id 1-5 line 6-7 v1 8-15
/2 v2 19-21 v3 58-59 v4 79-83 (A)
/3 v5 20 (A)
/11 v6 20-24.


Data List will read 11 records from d:\data\multiple-line.txt

Variable          Rec   Start     End  Format
id                  1       1       5  F5.0
line                1       6       7  F2.0
v1                  1       8      15  F8.0
v2                  2      19      21  F3.0
v3                  2      58      59  F2.0
v4                  2      79      83  A5
v5                  3      20      20  A1
v6                 11      20      24  F5.0


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.