Missing Values (LOOP-END LOOP command)
- If the program encounters a case with a missing value
for the initial, terminal, or increment value or expression, or if
the conditional expression on the
LOOP
command returns missing, a zero-trip loop results and control is passed to the first command after theEND LOOP
command. - If a case has a missing value for the conditional
expression on an
END LOOP
command, the loop is terminated after the first iteration. - To prevent cases with missing values for any variable
used in the loop structure from entering the loop, use the
IF
clause on theLOOP
command (see third example below).
Example
LOOP #I=1 TO Z IF (Y GT 10). /*Loop to X=Z for cases with Y GT 10
COMPUTE X=X+1.
END LOOP.
- The value of X remains unchanged for cases with a missing value for Y or a missing value for Z (or if Z is less than 1).
Example
MISSING VALUES X(5).
LOOP.
COMPUTE X=X+1.
END LOOP IF (X GE 10). /*Loop until X is at least 10 or missing
- Looping is terminated when the value of X is 5 because 5 is defined as missing for X.
Example
LOOP IF NOT MISSING(Y). /*Loop only when Y isn't missing
COMPUTE X=X+Y.
END LOOP IF (X GE 10). /*Loop until X is at least 10
- The variable X is unchanged for cases with a missing value for Y, since the loop is never entered.