SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Understanding DATA Step Processing
Lesson Summary

This page contains


I. Text Summary

To go to the page where a task, programming feature, or concept was presented, select a link.

DATA Step Processing
A SAS DATA step is processed in two distinct phases. During the compilation phase, each statement is scanned for syntax errors. During the execution phase, the DATA step writes observations to the new data set.

Compilation Phase
At the beginning of the compilation phase, the program data vector is created. This is the area of memory where data sets are built, one observation at a time. Two automatic variables are also created: _N_ counts the number of DATA step executions, and _ERROR_ signals the occurrence of an error. DATA step statements are checked for syntax errors, such as invalid options or misspellings.

Execution Phase
During the execution phase, each observation in the input data set is processed, stored in the program data vector, and then written to the new data set as an observation. The DATA step executes once for each observation in the input data set, unless otherwise directed.

Diagnosing Syntax Errors
Missing semicolons, misspelled keywords, and invalid options will cause syntax errors in the compilation phase. Detected errors are underlined and identified with a number and message in the log. If SAS software can interpret a syntax error, the DATA step compiles and executes; if SAS software cannot interpret the error, the DATA step compiles but doesn't execute.

Diagnosing Execution-Time Errors
Illegal mathematical operations or processing a character variable as numeric will cause errors in the execution phase. Depending on the type of error, the log may show a warning with invalid data from the program data vector, and the DATA step may either stop or continue.


II. Syntax

To go to the page where a statement or option was presented, select a link.

DATA <SAS-data-set>;
INFILE fileref;
INPUT variable-1 informat-1 input-pointer-control-1
           < . . .variable-n informat-n
           input-pointer-control-n>;
assignment statement;
RUN;


III. Sample Programs
     data perm.update;
        infile invent;
        input Item $ 1-13 IDnum 15-19
              InStock 21-22 BackOrd 24-25;
        Total=instock+backord;
     run;


IV. Points to Remember
  • Making, diagnosing, and resolving errors is part of the process of writing programs. However, checking for common errors will save you time and trouble. Make sure that

    • all SAS statements end with a semicolon
    • file names are spelled correctly
    • keywords are spelled correctly.

  • In SAS output, missing numeric values are represented by a period and missing character values are simply left blank.

  • The order in which variables are defined in the DATA step determines the order in which the variables are stored in the data set.

  • Standard character values can include numbers, but numeric values cannot include characters.


back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement