OBS= Data Set Option

Specifies the last observation that SAS processes in a data set.

Valid in: DATA step and PROC steps
Category: Observation Control
Default: MAX
Restrictions: Use with input data sets only.
Cannot use with PROC SQL views

Syntax

OBS= n | nK | nM | nG | nT | hexX | MIN | MAX

Syntax Description

n | nK | nM | nG | nT

specifies a number to indicate when to stop processing observations, with n as an integer. Using one of the letter notations results in multiplying the integer by a specific value. That is, specifying K (kilo) multiplies the integer by 1,024; M (mega) multiplies by 1,048,576; G (giga) multiplies by 1,073,741,824; or T (tera) multiplies by 1,099,511,627,776. For example, a value of 20 specifies 20 observations, and a value of 3m specifies 3,145,728 observations.

hexX

specifies a number to indicate when to stop processing as a hexadecimal value. You must specify the value beginning with a number (0–9), followed by an X. For example, the hexadecimal value F8 must be specified as 0F8x in order to specify the decimal equivalent of 248. The value 2dx specifies the decimal equivalent of 45.

MIN

specifies the number to indicate when to stop processing to 0. Use OBS=0 to create an empty data set that has the structure, but not the observations, of another data set.

Interaction If OBS=0 and the NOREPLACE option is in effect, SAS can still take certain actions. SAS actually executes each DATA and PROC step in the program, using no observations. For example, SAS executes procedures, such as CONTENTS and DATASETS, that process libraries or SAS data sets.

MAX

specifies the number to indicate when to stop processing to the maximum number of observations in the data set. This number can be up to the largest 8-byte, signed integer, which is 263–1, or approximately 9.2 quintillion. This is the default.

Details

OBS= tells SAS when to stop processing observations. To determine when to stop processing, SAS uses the value for OBS= in a formula that includes the value for OBS= and the value for FIRSTOBS=.
(obs - firstobs) + 1 = results
For example, if OBS=10 and FIRSTOBS=1 (which is the default for FIRSTOBS=), the result is 10 observations. That is, (10 - 1) + 1 = 10. If OBS=10 and FIRSTOBS=2, the result is nine observations. That is, (10 - 2) + 1 = 9. OBS= is valid only when an existing SAS data set is read.
The OBS= data set option overrides the OBS= system option for the individual data set.

Comparisons

  • When the OBS= data set option specifies an ending point for processing, the FIRSTOBS= data set option specifies a starting point. The two options are often used together to define a range of observations to be processed.
  • The OBS= data set option enables you to select observations from SAS data sets. You can select observations to be read from external data files by using the OBS= option in the INFILE statement.

Examples

Example 1: Using OBS= to Specify 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= appears to be the observation number that SAS processes last.
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=
PROC PRINT Output Using OBS= and FIRSTOBS=

Example 2: PROC PRINT Using a WHERE Statement

This example uses the data set that was created in Example 1, which contains 15 observations.
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
PROC PRINT Output Using a WHERE Statement

Example 3: PROC PRINT Using a WHERE Statement and OBS=

Executing the PRINT procedure with the WHERE statement and OBS=10 results in 10 observations. That is, (10 - 1) + 1 = 10. With WHERE processing, SAS 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=
PROC PRINT Output Using a WHERE Statement and OBS=

Example 4: PROC PRINT Using a WHERE Statement, OBS=, and FIRSTOBS=

The result of OBS= appears to be the observation number that SAS processes. If you apply FIRSTOBS=2 and OBS=10 to the subset, then the result is nine observations. That is, (10 - 2) + 1 = 9. OBS= 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 a WHERE Statement, OBS=, and FIRSTOBS=
PROC PRINT output using a WHERE statement, OBS=, and FIRSTOBS=

Example 5: PROC PRINT Showing Deleted Observations

This example uses the data set that was created in Example 1, with observation 6 deleted.
Here is PROC PRINT output of the modified file:
proc print data=Ages;
run;
PROC PRINT Output Showing Observation 6 Deleted
PROC PRINT output showing observation 6 deleted

Example 6: PROC PRINT Using OBS=

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=
PROC PRINT Output Using OBS=

Example 7: Using OBS= When Observations Are Deleted

The result of OBS= appears to be the observation number that SAS processes. However, if you apply FIRSTOBS=2 and OBS=12, the result is 11 observations. That is, (12 - 2) + 1 = 11. OBS= 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=
PROC PRINT Output Using OBS= and FIRSTOBS=

See Also

Data Set Options:
Statements:
INFILE Statement in SAS Statements: Reference
WHERE Statement in SAS Statements: Reference
System Options:
OBS= System Option in SAS System Options: Reference