Now that the program is complete, here is how SAS processes
a DATA step that contains an iterative DO loop.
data perm.sales07;
infile data07;
input ID $ @;
do Quarter=1 to 4;
input Sales : comma. @;
output;
end;
run;
During the first iteration,
the value for ID is read and Quarter is initialized to 1
as
the loop begins to execute.
The INPUT statement
reads the first repeating field and assigns the value to Sales in
the program data vector. The @ holds the current record.
The OUTPUT statement
writes the values in the program data vector to the data set as the
first observation.
The END statement indicates
the bottom of the loop, but control returns to the DO statement, not
to the top of the DATA step. Now the value of Quarter is incremented
to 2
.
The INPUT statement
executes again, reading the second repeating field and storing the
value for Sales in the program data vector.
The OUTPUT statement
writes the values in the program data vector as the second observation.
The loop continues executing
while the value for Quarter is 3
, and
then 4
. In the process, the third and
fourth observations are written.
After the fourth observation
is written, Quarter is incremented to 5
at
the bottom of the DO loop and control returns to the top of the loop.
The loop does not execute again because the value of Quarter is now
greater than 4
.
Control returns to the
top of the DATA step, and the input pointer moves to column 1 of the
next record. The variable values in the program data vector are reset
to missing.
You can display the
data set with the PRINT procedure.
proc print data=perm.sales07;
run;