Example 3
SUBSET FROM(IN3) TO(OUT4) KEEP OUTPUT -
LAST(5) USING(CTL1)
This example illustrates how you can keep the last 5 sorted records.
The CTL1CNTL data set contains:
SORT FIELDS=(1,15,CH,A)The input records look like this:
Psychology
Biology
Russian
French
History
Geography
Calculus
Geometry
Algebra
Greek
Astronomy
LatinWe want to sort the records by the CH field in positions 1-15 and
keep the last 5 sorted records. We use KEEP, OUTPUT and LAST(5) to
keep the last 5 output records. We use the SORT statement to sort
the records before they are output. After the SORT statement is executed,
the intermediate records look like this:
Algebra
Astronomy
Biology
Calculus
French
Geography
Geometry
Greek
History
Latin
Psychology
RussianAfter the SUBSET operator is executed, the final output records
look like this:
Greek
History
Latin
Psychology
RussianNote that we could use TRAILER(5) instead of LAST(5).