You can see that the DATA step works
like a loop, repetitively executing statements to read data values
and create observations one by one. At the beginning of the second
iteration, the value of _N_ is 2, and _ERROR_ is still 0. Each loop
(or cycle of execution) is called an iteration.
As the SET statement executes
for the second time, the values from the second record are read from
the input table into the PDV.
Next, the value for
Total is calculated based on the current values for InStock and BackOrd.
data work.update;
set cert.invent;
Total=instock+backord;
SalePrice=(CostPerUnit*0.65)+CostPerUnit;
format CostPerUnit SalePrice dollar6.2;
run;
Next, the value for
SalePrice is calculated based on the values for CostPerUnit, multiplied
by 0.65, and added to the value of CostPerUnit.
data work.update;
set cert.invent;
Total=instock+backord;
SalePrice=(CostPerUnit*0.65)+CostPerUnit;
format CostPerUnit SalePrice dollar6.2;
run;
The RUN statement indicates
the end of the DATA step loop. At the bottom of the DATA step, the
values in the PDV are written to the data set as the second observation.
data work.update;
set cert.invent;
Total=instock+backord;
SalePrice=(CostPerUnit*0.65)+CostPerUnit;
format CostPerUnit SalePrice dollar6.2;
run;
Next, the value of _N_
increments from 2 to 3, control returns to the top of the DATA step,
and the values for Item, IDnum, InStock, BackOrd, CostPerUnit, Total,
and SalePrice are reset to missing.
data work.update;
set cert.invent;
Total=instock+backord;
SalePrice=(CostPerUnit*0.65)+CostPerUnit;
format CostPerUnit SalePrice dollar6.2;
run;
When PROC IMPORT reads
raw data, SAS sets the value of each variable in the DATA step to
missing at the beginning of each cycle of execution, with these exceptions:
-
variables that are named in a RETAIN
statement
-
variables that are created in a
sum statement
-
In contrast, when reading
variables from a SAS data set, SAS sets the values to missing only
before the first cycle of execution of the DATA step. Therefore, the
variables retain their values until new values become available (for
example, through an assignment statement or through the next execution
of a SET or MERGE statement). Variables that are created with options
in a SET or MERGE statement also retain their values from one cycle
of execution to the next.