END Subcommand (DATA LIST command)

END provides control of end-of-file processing by specifying a variable that is set to a value of 0 until the end of the data file is encountered, at which point the variable is set to 1. The values of all variables named on DATA LIST are left unchanged. The logical variable created with END can then be used on DO IF and LOOP commands to invoke special processing after all of the cases from a particular input file have been built.

  • DATA LIST and the entire set of commands used to define the cases must be enclosed within an INPUT PROGRAM—END INPUT PROGRAM structure. The END FILE command must also be used to signal the end of case generation.
  • END can be used only with fixed-format data. An error is generated if the END subcommand is used with FREE or LIST.

Example

INPUT PROGRAM.
NUMERIC        TINCOME (DOLLAR8.0).                 /* Total income
LEAVE          TINCOME.
DO IF          $CASENUM EQ 1.
+  PRINT       EJECT.
+  PRINT       / 'Name        Income'.
END IF
DATA LIST     FILE=INCOME END=#EOF NOTABLE / NAME 1-10(A) 
                                             INCOME 16-20(F).
DO IF          #EOF.
+  PRINT       / 'TOTAL     ', TINCOME.
+  END FILE.
ELSE.
+  PRINT       / NAME, INCOME (A10,COMMA8).
+  COMPUTE     TINCOME = TINCOME+INCOME.  /* Accumulate total income
END IF.
END INPUT PROGRAM.
 
EXECUTE.
  • The data definition commands are enclosed within an INPUT PROGRAM—END INPUT PROGRAM structure.
  • NUMERIC indicates that a new numeric variable, TINCOME, will be created.
  • LEAVE tells the program to leave variable TINCOME at its value for the previous case as each new case is read, so that it can be used to accumulate totals across cases.
  • The first DO IF structure, enclosing the PRINT EJECT and PRINT commands, tells the program to display the headings Name and Income at the top of the display (when $CASENUM equals 1).
  • DATA LIST defines variables NAME and INCOME, and it specifies the scratch variable #EOF on the END subcommand.
  • The second DO IF prints the values for NAME and INCOME and accumulates the variable INCOME into TINCOME by passing control to ELSE as long as #EOF is not equal to 1. At the end of the file, #EOF equals 1, and the expression on DO IF is true. The label TOTAL and the value for TINCOME are displayed, and control is passed to END FILE.

Example

* Concatenate three raw data files.

INPUT PROGRAM.
NUMERIC #EOF1 TO #EOF3.  /*These will be used as the END variables.

DO IF #EOF1 & #EOF2 & #EOF3.
+   END FILE.
ELSE IF #EOF1 & #EOF2.
+    DATA LIST  FILE=THREE END=#EOF3 NOTABLE / NAME 1-20(A)
             AGE 25-26 SEX 29(A).
+    DO IF NOT #EOF3.
+       END CASE.
+    END IF.
ELSE IF #EOF1.
+    DATA LIST  FILE=TWO END=#EOF2 NOTABLE / NAME 1-20(A)
             AGE 21-22 SEX 24(A).
+    DO IF NOT #EOF2.
+       END CASE.
+    END IF.
ELSE.
+    DATA LIST  FILE=ONE END=#EOF1 NOTABLE /1 NAME 1-20(A)
             AGE 21-22 SEX 24 (A).
+    DO IF NOT #EOF1.
+       END CASE.
+    END IF.
END IF.
END INPUT PROGRAM.

REPORT FORMAT AUTOMATIC LIST /VARS=NAME AGE SEX.
  • The input program contains a DO IF—ELSE IF—END IF structure.
  • Scratch variables are used on each END subcommand so the value will not be reinitialized to the system-missing value after each case is built.
  • Three data files are read, two of which contain data in the same format. The third requires a slightly different format for the data items. All three DATA LIST commands are placed within the DO IF structure.
  • END CASE builds cases from each record of the three files. END FILE is used to trigger end-of-file processing once all data records have been read.