At compile time, the
variable Type is flagged so that its values are not written to the
data set. Address is flagged so that its value is retained across
iterations of the DATA step.
data perm.people (drop=type);
infile census;
retain Address;
input type $1. @;
if type='H' then input @3 address $15.;
if type='P';
input @3 Name $10. @13 Age 3. @16 Gender $1.;
run;
As the DATA step begins
to execute, the INPUT statement reads the value for Type and holds
the first record.
The condition Type='H'
is checked and found to be true. Therefore, the INPUT statement reads
the value for Address in the first record.
Next, the subsetting
IF statement checks for the condition Type='P'. Because the condition
is not true, the remaining statements are not executed and control
returns to the top of the DATA step. The PDV is initialized but Address
is retained.
As the second iteration
begins, the input pointer moves to the next record and a new value
for Type is read. The condition expressed in the IF-THEN statement
is not true, so the statement following the THEN keyword is not executed.
Now the subsetting IF
statement checks for the condition Type='P'. In this iteration, the
condition is true, so the final INPUT statement reads the values for
Name, Age, and Gender.
Next, the values in
the program data vector are written as the first observation, and
control returns to the top of the DATA step. Notice that the values
for Type are not included.
As execution continues,
observations are produced from the third and fourth records. However,
notice that the fifth record is a header record. During the fifth
iteration, the condition Type='H' is true, so a new address is read
into the program data vector, overwriting the previous value.