Examples (END FILE command)
Stop reading a file based on a data value
*Select cases.
INPUT PROGRAM.
DATA LIST FILE=PRICES /YEAR 1-4 QUARTER 6 PRICE 8-12(2).
DO IF (YEAR GE 1881). /*Stop reading before 1881
END FILE.
END IF.
END INPUT PROGRAM.
LIST.
- This example assumes that data records are entered chronologically
by year. The
DO IF—END IF
structure specifies an end of file when the first case with a value of 1881 or later for YEAR is reached. -
LIST
executes the input program and lists cases in the active dataset. The case that causes the end of the file is not included in the active dataset. - As an alternative to an input program with
END FILE
, you can useN OF CASES
to select cases if you know the exact number of cases. Another alternative is to useSELECT IF
to select cases before 1881, but then the program would unnecessarily read the entire input file.
END FILE with END CASE
*Select cases but retain the case that causes end-of-file processing.
INPUT PROGRAM.
DATA LIST FILE=PRICES /YEAR 1-4 QUARTER 6 PRICE 8-12(2).
DO IF (YEAR GE 1881). /*Stop reading before 1881 (or at end of file)
END CASE. /*Create case 1881
END FILE.
ELSE.
END CASE. /*Create all other cases
END IF.
END INPUT PROGRAM.
LIST.
- The first
END CASE
command forces the program to retain the case that causes end-of-file processing. - The second
END CASE
indicates the end of case for all other cases and passes them out of the input program one at a time. It is required because the firstEND CASE
command causes the program to abandon default end-of-case processing (seeEND CASE
).