Example 1: Using OBS= to Specify When to Stop Processing Observations
This example illustrates
the result of using OBS= to tell SAS when to stop processing observations.
This example creates a SAS data set and executes the PRINT procedure
with FIRSTOBS=2 and OBS=12. The result is 11 observations, that is
(12 - 2) + 1 = 11
. The result of OBS= in this situation
appears to be the observation number that SAS processes last, because
the output starts with observation 2, and ends with observation 12.
This situation is only a coincidence.
data Ages;
input Name $ Age;
datalines;
Miguel 53
Brad 27
Willie 69
Marc 50
Sylvia 40
Arun 25
Gary 40
Becky 51
Alma 39
Tom 62
Kris 66
Paul 60
Randy 43
Barbara 52
Virginia 72
;
proc print data=Ages (firstobs=2 obs=12);
run;
PROC PRINT Output Using OBS= and FIRSTOBS=
Example 2: Using OBS= with WHERE Processing
This example illustrates
the result of using OBS= along with WHERE processing. The example
uses the data set that was created in Example 1, which contains 15
observations.
First, here is the PRINT
procedure with a WHERE statement. The subset of the data results in
12 observations:
proc print data=Ages;
where Age LT 65;
run;
PROC PRINT Output Using a WHERE Statement
Executing the PRINT
procedure with the WHERE statement and OBS=10 results in 10 observations,
that is
(10 - 1) + 1 = 10
. Note that
with WHERE processing, SAS first subsets the data and applies OBS=
to the subset.
proc print data=Ages (obs=10);
where Age LT 65;
run;
PROC PRINT Output Using a WHERE Statement and OBS=
The result of OBS= appears
to be how many observations to process, because the output consists
of 10 observations, ending with the observation number 12. However,
the result is only a coincidence. If you apply FIRSTOBS=2 and OBS=10
to the subset, then the result is nine observations, that is
(10 - 2) + 1 = 9
. OBS= in this situation is neither
the observation number to end with nor how many observations to process;
the value is used in the formula to determine when to stop processing.
proc print data=Ages (firstobs=2 obs=10);
where Age LT 65;
run;
PROC PRINT Output Using WHERE Statement, OBS=, and FIRSTOBS=
This example
illustrates the result of using OBS= for a data set that has deleted
observations. The example uses the data set that was created in Example
1, with observation 6 deleted.
First, here is PROC
PRINT output of the modified file:
proc print data=Ages;
run;
PROC PRINT Output Showing Observation 6 Deleted
Executing the PRINT
procedure with OBS=12 results in 12 observations, that is
(12 - 1) + 1 = 12
:
proc print data=Ages (obs=12);
run;
PROC PRINT Output Using OBS=
Example 3: Using OBS= When Observations Are Deleted
The result of OBS= appears
to be how many observations to process, because the output consists
of 12 observations, ending with the observation number 13. However,
if you apply FIRSTOBS=2 and OBS=12, the result is 11 observations,
that is
(12 - 2) + 1 = 11
. OBS= in
this situation is neither the observation number to end with nor how
many observations to process; the value is used in the formula to
determine when to stop processing.
proc print data=Ages (firstobs=2 obs=12);
run;
PROC PRINT Output Using OBS= and FIRSTOBS=