Processing a DATA Step That Creates One Observation per Header
Record
During the compilation
phase, the variable type is flagged so that later it can be dropped.
The value for Address and Total (sum statement) are retained.
As the execution begins,
_N_ is 1 and Last is 0. Total is 0 because of the sum statement.
The value for Type is
read, the condition type='H' is true, and therefore the statements
in the DO group execute.
The condition N>1
is not true, so the OUTPUT statement is not executed. However, Total
is assigned the value of 0 and the value for Address is read.
The END statement closes
the DO group. The alternative condition expressed in the ELSE statement
is not checked because the first condition, Type='H', was true.
The value of Last is
still 0, so the OUTPUT statement is
not executed. Control returns to the top of the DATA step.
During the second iteration,
the value of type is 'P' and Total
is incremented by 1. Again, the value of Last is 0,
so control returns to the top of the DATA step.
During the fifth iteration,
the value of Type is 'H' and _N_ is
greater than 1, so the values for Address and Total are written to
the data set as the first observation.
As the last record in
the file is read, the variable Last is set to 1.
Now that the condition for Last is true, the values in the program
data vector are written to the data set as the final observation.