Question-46: What is the SAS automatic variable?

Answer: During the Data step SAS creates a program data vector which can hold actual observation as well as two automatic variables named _N_ and _ERROR_

Where

  • _N_: holds how many times data step is iterated.
  • _ERROR_: During the execution phase if there are any error happened or not.

Both the automatic variable can only be populated during the execution phase.

 

Question-47: What is the execution phase?

Answer: During the compilation phase only machine instructions and logical memory (input buffer, program data vector) would be created but they would not be executed. Machine instructions would be executed during the execution phase only. Suppose your raw file has 1000 records then your data step would be compiled only once but executed 1000 times, once for each record.

 

Question-48: What would happen during the execution phase of the data step?

Answer: During the execution phase of data step following things would be done in each iteration

  • SAS reads raw record in input buffer.
  • Assign values from record in the program vector and in the specific variable.
  • If you are creating a new variable in the program by applying some calculation then this would also be created in the program data vector.
  • Once all the records iteration is done then following 3 things would be done at the end of each execution step
    • Dumping the program data vector (one observation) in the SAS data set
    • Program go back to the next record and start from the Data step again.
    • Variable in the program data vector are specified or reset to missing values.
  • Following two things would not be reset in each iteration
    • Automatic variable _N_ and _ERROR_
    • If you have specified any variable with the RETAIN statement
  • Once all the records are processed and SAS data set would be closed for further write, and SAS goes to next DATA or PROC step, if specified as next.

Question-49: What is the use of automatic variable generated in the Data step?

Answer: There are two automatic variables generated in the Data step which are as below, this both variables has initial value set as missing. As on when Data step process each step they are updated accordingly

  • _N_ : It represents how many time DATA step has been iterated.
  • _ERROR_ : It has binary value either 0 or 1 , if while processing the records if there is any error then this would be set as 1 else remain 0.

Both of this variable are not printed as output, once the DATA step completed.

 

Question-50: Can SAS proc process the RAW data directly?

Answer:  Generally, not, your RAW data first needs to be converted into SAS Dataset then SAS proc can process this SAS Dataset.