How to: |
The LAST function retrieves the preceding value for a field.
The effect of LAST depends on whether it appears in a DEFINE or COMPUTE command:
Do not use LAST with the -SET command in Dialogue Manager.
LAST fieldname
where:
Alphanumeric or Numeric
Is the field name.
Note: LAST does not use an output argument.
LAST retrieves the previous value of the DEPARTMENT field to determine whether to restart the running total of salaries by department. If the previous value equals the current value, CURR_SAL is added to RUN_TOT to generate a running total of salaries within each department.
TABLE FILE EMPLOYEE PRINT LAST_NAME CURR_SAL AND COMPUTE RUN_TOT/D12.2M = IF DEPARTMENT EQ LAST DEPARTMENT THEN (RUN_TOT + CURR_SAL) ELSE CURR_SAL ; AS 'RUNNING,TOTAL,SALARY' BY DEPARTMENT SKIP-LINE END
The output is:
RUNNING TOTAL DEPARTMENT LAST_NAME CURR_SAL SALARY ---------- --------- -------- ------- MIS SMITH $13,200.00 $13,200.00 JONES $18,480.00 $31,680.00 MCCOY $18,480.00 $50,160.00 BLACKWOOD $21,780.00 $71,940.00 GREENSPAN $9,000.00 $80,940.00 CROSS $27,062.00 $108,002.00 PRODUCTION STEVENS $11,000.00 $11,000.00 SMITH $9,500.00 $20,500.00 BANNING $29,700.00 $50,200.00 IRVING $26,862.00 $77,062.00 ROMANS $21,120.00 $98,182.00 MCKNIGHT $16,100.00 $114,282.00