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.
filename invent 'Z:sasuserinvent.dat';
data work.update;
	infile invent;
	input Item $1-13 IDnum $15-19
	InStock 21-22 BackOrd 24-25;
	Total=instock+backord;
run;
Program Data Vector
The remaining variables are initialized to missing. Missing numeric values are represented by periods, and missing character values are represented by blanks.

INFILE Statement

The INFILE statement identifies the location of the raw data.
filename invent 'Z:sasuserinvent.dat';
data work.update;
	infile invent;
	input Item $1-13 IDnum $15-19
	InStock 21-22 BackOrd 24-25;
	Total=instock+backord;
run;

INPUT Statement

After that, the INPUT statement reads a record into the input buffer. Then, the raw data in columns 1-13 is read and is assigned to Item in the program data vector.
data work.update;
   infile invent; 
   input Item $ 1-13 IDnum $ 15-19 
         InStock 21-22 BackOrd 24-25; 
   Total=instock+backord; 
run;
Raw Data File Invent
Next, the data in columns 15-19 is read and is assigned to IDnum in the program data vector.
data work.update; 
   infile invent; 
   input Item $ 1-13 IDnum $ 15-19 
         InStock 21-22 BackOrd 24-25;
   Total=instock+backord; 
run;
Raw Data File Invent
Likewise, the INPUT statement reads the values for InStock from columns 21-22, and it reads the values for BackOrd from columns 24-25.
data work.update; 
   infile invent; 
   input Item $ 1-13 IDnum $ 15-19 
         InStock 21-22 BackOrd 24-25; 
   Total=instock+backord; 
run;
Raw Data File Invent
Next, the assignment statement executes. The values for InStock and BackOrd are added to produce the values for Total.
data work.update; 
  infile invent; 
  input Item $ 1-13 IDnum $ 15-19 
        InStock 21-22 BackOrd 24-25; 
 Total=instock+backord; 
run;
Raw Data File Invent

End of the DATA Step

At the end of the DATA step, several actions occur. First, the values in the program data vector are written to the output data set as the first observation.
data work.update; 
   infile invent;
   input Item $ 1-13 IDnum $ 15-19 
         InStock 21-22 BackOrd 24-25; 
   Total=instock+backord; 
run;
Raw Data File Invent
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 program data vector are reset to missing. Notice that the automatic variable _ERROR_ is reset to 0 if necessary.
data work.update; 
   infile invent; 
   input Item $ 1-13 IDnum $ 15-19 
         InStock 21-22 BackOrd 24-25; 
   Total=instock+backord; 
run;
Raw Data File Invent

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.4 Iterations of the DATA Step
Iterations of the Data Step
As the INPUT statement executes for the second time, the values from the second record are read into the input buffer and then into the program data vector.
Raw Data File Invent
Next, the value for Total is calculated based on the current values for InStock and BackOrd. The RUN statement indicates the end of the DATA step loop.
data work.update; 
   infile invent; 
   input Item $ 1-13 IDnum $ 15-19 
         InStock 21-22 BackOrd 24-25; 
   Total=instock+backord; 
run;
Raw Data File Invent
At the bottom of the DATA step, the values in the program data vector are written to the data set as the second observation.
data work.update; 
   infile invent; 
   input Item $ 1-13 IDnum $ 15-19 
         InStock 21-22 BackOrd 24-25; 
   Total=instock+backord; 
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, and Total are reset to missing.
data work.update;
   infile invent; 
   input Item $ 1-13 IDnum $ 15-19 
         InStock 21-22 BackOrd 24-25; 
   Total=instock+backord; 
run;
Raw Data File Invent

End-of-File Marker

The execution phase continues in this manner until the end-of-file marker is reached in the raw data file. When there are no more records in the raw data file to be read, the data portion of the new data set is complete and the DATA step stops.
Raw Data File Invent
This is the output data set that SAS creates:
Figure 7.5 SAS Data Set Work.Update
SAS Data Set Work.Update
When reading variables from 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
  • data elements in a _TEMPORARY_ array
  • any variables that are created with options in the FILE or INFILE statements
  • 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 the SET or MERGE statements also retain their values from one cycle of execution to the next.

End of the Execution Phase

At the end of the execution phase, the SAS log confirms that the raw data file was read, and it displays the number of observations and variables in the data set.
Log 7.1 SAS Log
NOTE: 9 records were read from the infile INVENT.
	     The minimum record length was 80.
			 The maximum record length was 80.
NOTE: The data set WORK.UPDATE has 9 observations and 5 variables. 
Recall that you can display the data set with the PRINT procedure.
proc print data=work.update; 
run;
Figure 7.6 Output from the PRINT Procedure
Output from the PRINT Procedure
Last updated: January 10, 2018
..................Content has been hidden....................

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