Items with multiple occurrences or in multiple records have one name (the item name), but can occur multiple times. In order to indicate the specific occurrence of the item, you may need to use an index or subscript. The subscripts are integers and are numbered from 1.
Imagine that the SEX is an item in the multiple record CHILD.
The expressions:
SEX(1) | refers to the sex of the first child |
SEX(3) | refers to the sex of the third child |
SEX(i) | refers to the sex of the i-th child |
Subscripts can be numeric expressions as well as numeric constants. For example, the expression:
refers to the current occurrence of CHILD (
curocc is a function that returns the current occurrence of a multiple record). When referring to multiply-occurring items within the scope of their repetition, you do not need to use subscripts, as the current occurrence will be assumed. For example, suppose you have a population record that has multiple occurrences. Belonging to that record are the three variables SEX, AGE, and FERTILITY. If your code is located within any of these variables' procedures, you do not need to use subscripts. To illustrate:
However, if you were to place the exact same logic elsewhere in your program, you would have to programmatically mimic the looping mechanism by using subscripts. For example, if the above code were placed in the QUEST procedure (where QUEST is equivalent to the case), it would need to be adjusted as follows:
On the other hand, it simplified our logic for the row number, as we don't need to make a call to
curocc anymore to find out what row we're on—we know it now, as we're controlling the looping.