Execution Phase

Initializing Variables

At the beginning of the execution phase, the value of _N_ is 1. Because there are no data errors, the value of _ERROR_ is 0.
data work.update;
  set cert.invent;
  Total=instock+backord;
  SalePrice=(CostPerUnit*0.65)+CostPerUnit;
  format CostPerUnit SalePrice dollar6.2;
run;
Figure 7.6 Program Data Vector: Initializing Variables
Program Data Vector: Initializing Variables
The remaining variables are initialized to missing. Missing numeric values are represented by periods, and missing character values are represented by blanks.

SET Statement

The SET statement identifies the location of the input data set. Columns are added to the PDV in the order in which they appear in the input table. Attributes are inherited from the input table.
data work.update;
  set cert.invent;
  Total=instock+backord;
  SalePrice=(CostPerUnit*0.65)+CostPerUnit;
  format CostPerUnit SalePrice dollar6.2;
run;

Sequentially Process Statements

After the SET statement, SAS executes the remaining statements sequentially and updates the values in the PDV.
data work.update;
  set cert.invent;
  Total=instock+backord;                        /*#1*/
  SalePrice=(CostPerUnit*0.65)+CostPerUnit;     /*#2*/
  format CostPerUnit SalePrice dollar6.2;
run;
1 SAS processes the first assignment statement to create the new variable, Total. The values of InStock and BackOrd are added together to create a value for Total. See PDV: Create a New Variable, Total below for a visual representation of how the PDV processes the first assignment statement.
2 SAS processes the second assignment statement to create the new variable, SalePrice. The value of CostPerUnit is multiplied by 0.65, and the resulting value is added to the value of CostPerUnit to create a value for SalePrice. See PDV: Create a New Variable, SalePrice below for a visual representation of how the PDV processes the second assignment statement.
Figure 7.7 PDV: Create a New Variable, Total
Program Data Vector
Figure 7.8 PDV: Create a New Variable, SalePrice
Program Data Vector
The formats for each variable are applied before SAS adds the values to the PDV.

End of the DATA Step

At the end of the DATA step, several actions occur. First, the values in the PDV are written to the output data set as the first observation.
data work.update;
  set cert.invent;
  Total=instock+backord;
  SalePrice=(CostPerUnit*0.65)+CostPerUnit;
  format CostPerUnit SalePrice dollar6.2;
run;
Figure 7.9 Program Data Vector and Output Data Set
Program Data Vector and Output
Next, control returns to the top of the DATA step, and the value of _N_ increments from 1 to 2. Finally, the variable values in the PDV are reset to missing. Notice that the automatic variable _ERROR_ is reset to 0 if necessary.
data work.update;
  set cert.invent;
  Total=instock+backord;
  SalePrice=(CostPerUnit*0.65)+CostPerUnit;
  format CostPerUnit SalePrice dollar6.2;
run;
Figure 7.10 Program Data Vector and Output Data Set
Program Data Vector and Output Data Set

Iterations of the DATA Step

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.
Figure 7.11 Iterations of the DATA Step
Iterations of the DATA Step
As the SET statement executes for the second time, the values from the second record are read from the input table into the PDV.
Figure 7.12 Program Data Vector and Output Data Set
Program Data Vector and Output Data Set
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;
Figure 7.13 Program Data Vector and Output Data Set
Program Data Vector and Output Data Set
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;
Figure 7.14 Program Data Vector and Output Data Set
Program Data Vector and Output Data Set
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;
Figure 7.15 Program Data Vector and Output Data
Program Data Vector and Output Data Set
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
  • automatic variables
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.

End-of-File Marker

The execution phase continues in this manner until the end-of-file marker is reached in the input data file. When there are no more records in the input data file to be read, the data portion of the new data set is complete and the DATA step stops.
This is the output data set that SAS creates:
Figure 7.16 SAS Data Set Work.Update
SAS Data Set Work.Update

End of the Execution Phase

At the end of the execution phase, the SAS log confirms that the input data file was read, and it displays the number of observations and variables in the data set.
Log 7.1 SAS Log
NOTE: There were 9 observations read from the data set
      CERT.INVENT.
NOTE: The data set WORK.UPDATE has 9 observations and 7
      variables.
Recall that you can display the data set with the PRINT procedure.
proc print data=work.update; 
run;
Output 7.1 Output from the PRINT Procedure
Output from the PRINT Procedure
Last updated: August 23, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.52.203