Understanding
step boundaries is an important concept in SAS programming because
step boundaries determine when SAS statements take effect. SAS executes
program statements only when SAS crosses a default or a step boundary.
Consider the following DATA steps:
data _null_; 1
set allscores(drop=score5-score7);
title 'Student Test Scores'; 2
data employees; 3
set employee_list;
run;
1 |
The
DATA statement begins a DATA step and is a step boundary.
|
2 |
The
TITLE statement is in effect for both DATA steps because it appears
before the boundary of the first DATA step. (The TITLE statement is
a global statement.)
|
3 |
The
DATA statement is the default boundary for the first DATA step.
|
The TITLE statement
in this example is in effect for the first DATA step as well as for
the second because the TITLE statement appears before the boundary
of the first DATA step. This example uses the default step boundary
data
employees;
.
The following example
shows an OPTIONS statement inserted after a RUN statement.
data scores; 1
set allscores(drop=score5-score7);
run; 2
options firstobs=5 obs=55; 3
data test;
set alltests;
run;
1 |
The
DATA statement is a step boundary.
|
2 |
The
RUN statement is the boundary for the first DATA step.
|
3 |
The
OPTIONS statement affects the second DATA step only.
|
The OPTIONS statement
specifies that the first observation that is read from the input data
set should be the 5th, and the last observation that is read should
be the 55th. Inserting a RUN statement immediately before the OPTIONS
statement causes the first DATA step to reach its boundary (
run;
)
before SAS encounters the OPTIONS statement. The OPTIONS statement
settings, therefore, are put into effect for the second DATA step
only.
Following the statements
in a DATA step with a RUN statement is the simplest way to make the
step begin to execute, but a RUN statement is not always necessary.
SAS recognizes several step boundaries for a SAS step:
-
-
-
Note: For SAS programs executed
in interactive mode, a RUN statement is required to signal the step
boundary for the last step that you submit.
-
the semicolon (with a DATALINES
or CARDS statement) or four semicolons (with a DATALINES4 or CARDS4
statement) after data lines
-
-
in noninteractive or batch mode,
the end of a program file containing SAS programming statements
-
a QUIT statement (for some procedures)
When you submit a DATA
step during interactive processing, it does not begin running until
SAS encounters a step boundary. This fact enables you to submit statements
as you write them while preventing a step from executing until you
have entered all the statements.