OCCURS Subcommand (REPEATING DATA command)
OCCURS
specifies
the number of repeating groups for each input case. OCCURS
is
required and specifies a number if the number of groups is the same for all
input cases or a variable if the number of groups varies across input cases.
The variable must be defined on a DATA LIST
command
or created with transformation commands.
Specifying the Number of Repeating Groups Using a Data Field
INPUT PROGRAM.
DATA LIST / SEQNUM 2-4 NUMPERS 6-7 NUMVEH 9-10.
REPEATING DATA STARTS=12 /OCCURS=NUMVEH
/DATA=MAKE 1-8 (A) MODEL 9 (A) NUMCYL 10.
END INPUT PROGRAM.
BEGIN DATA
1001 02 02 FORD T8PONTIAC C6
1002 04 01 CHEVY C4
1003 02 03 CADILAC C8FORD T6VW C4
END DATA.
LIST.
- Data for each input case are recorded on a single record; there are no continuation records.
- The value for variable NUMVEH in columns 9 and 10 indicates the number of repeating groups on each record. One output case is built in the active dataset for each occurrence of a repeating group.
- In the data, NUMVEH has the value 2 for the first case, 1 for the second, and 3 for the third. Thus, six cases are built from these records. If the value of NUMVEH is 0, no cases are built from that record.
Specifying a Fixed Number of Repeating Groups
* Read only the first repeating group from each record.
INPUT PROGRAM.
DATA LIST FILE=VEHICLE / SEQNUM 2-4 NUMPERS 6-7 NUMVEH 9-10.
REPEATING DATA STARTS=12 /OCCURS=1
/DATA=MAKE 1-8 (A) MODEL 9 (A) NUMCYL 10.
END INPUT PROGRAM.
LIST.
- Since
OCCURS
specifies that there is only one repeating group for each input case, only one output case is built from each input case regardless of the actual number of repeating groups.