This example uses
the following DATA step:
data perm.sales08;
infile data08 missover;
input ID $ Sales : comma. @;
Quarter=0;
do while (sales ne .);
quarter+1;
output;
input sales : comma. @;
end;
run;
During the first iteration
of the DATA step, values for ID and Sales are read. Quarter is initialized
to 0
.
The DO WHILE statement
checks to see whether Sales has a value, which it does, so the other
statements in the DO loop execute. The Value of Quarter is incremented
by 1 and the current observation is written to the data set.
The INPUT statement
reads the next value for Sales, the end of the loop is reached, and
control returns to the DO WHILE statement.
The condition is checked
and Sales still has a value, so the loop executes again.
Quarter is incremented
to 2, and the values in the program data vector are written as the
second observation.
The INPUT statement
executes again. The MISSOVER option prevents the input pointer from
moving to the next record in search of another value for Sales. Therefore,
Sales receives a missing value.
The end of the loop
is reached, and control returns to the DO WHILE statement. Because
the condition is now false, the statements in the loop are not executed
and the values in the PDV are not written to output.
Instead, control returns
to the top of the DATA step, the values in the program data vector
are reset to missing, and the INPUT statement reads the next record.
The DATA step continues executing until the end of the file.
PROC PRINT output for
the data set shows a varying number of observations for each employee.
proc print data=perm.sales08;
run;