Fixed Number of Repeating Groups
The following table shows test score data for students in three classrooms. Each record contains a classroom number and two pairs of student ID and test score variables. For example, in class 101, student 182 has a score of 12 and student 134 has a score of 53. In class 103, student 15 has a score of 87 and student 203 has a score of 69. Each pair of ID and score variables is a repeating group, since these variables appear twice on each record.
Class | ID | Score | ID | Score |
---|---|---|---|---|
101 | 182 | 12 | 134 | 53 |
102 | 99 | 112 | 200 | 150 |
103 | 15 | 87 | 203 | 69 |
The following commands generate a active dataset in which one case is built for each occurrence of SCORE and ID, and classroom number is spread to each case on a record.
INPUT PROGRAM.
DATA LIST / CLASS 3-5.
REPEATING DATA STARTS=6 / OCCURS=2
/DATA STUDENT 1-4 SCORE 5-8.
END INPUT PROGRAM.
BEGIN DATA
101 182 12 134 53
102 99 112 200 150
103 15 87 203 69
END DATA.
LIST.
-
INPUT PROGRAM
signals the beginning of data definition. -
DATA LIST
defines variable CLASS, which is spread to each student on a classroom record. -
REPEATING DATA
specifies that the input file contains repeating data.STARTS
indicates that repeating data begin in column 6.OCCURS
specifies that the repeating data group occurs twice in each record. -
DATA
defines variables that are repeated (STUDENT and SCORE). The program begins reading the first repeating data group in column 6 (the value ofSTARTS)
. Since the value ofOCCURS
is 2, the program reads the repeating variables a second time, beginning in the next available column (column 14). -
END INPUT PROGRAM
signals the end of data definition. -
BEGIN DATA
andEND DATA
specify that data are inline. - The output from
LIST
is shown below. Each student is a separate case.
CLASS STUDENT SCORE
101 182 12
101 134 53
102 99 112
102 200 150
103 15 87
103 203 69