FIRSTOBS= Data Set Option

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

Valid in: DATA step and PROC steps
Category: Observation Control
Restrictions: Valid for input (read) processing only.
Cannot use with PROC SQL views.

Syntax

FIRSTOBS=n | nK | nM | nG | hexX | MIN | MAX

Syntax Description

n | nK | nM | nG

specifies the number of the first observation to process in multiples of 1 (bytes); 1,024 (kilobytes); 1,048,576 (megabytes); or 1,073,741,824 (gigabytes). For example, a value of 8 specifies the 8th observation, and a value of 3k specifies 3,072.

hexX

specifies the number of the first observation to process as a hexadecimal value. You must specify the value beginning with a number (0–9), followed by an X. For example, the value 2dx sets the 45th observation as the first observation to process.

MIN

sets the number of the first observation to process to 1. This is the default.

MAX

sets the number of the first observation to process to the maximum number of observations in the data set. This number can be up to the largest eight-byte, signed integer, which is 263–1, or approximately 9.2 quintillion observations.

Details

The FIRSTOBS= data set option affects a single, existing SAS data set. Use the FIRSTOBS= system option to affect all steps for the duration of your current SAS session.
FIRSTOBS= is valid for input (read) processing only. Specifying FIRSTOBS= is not valid for output or update processing.
You can apply FIRSTOBS= processing to WHERE processing. For more information, see Processing a Segment of Data That Is Conditionally Selected in SAS Language Reference: Concepts.
If you delete data set observations by using the VIEWTABLE window, the FIRSTOBS= option gives incorrect results if the value assigned to the FIRSTOBS= option is greater than the number of the observation that were deleted. This behavior occurs because deleting data set observations by using the VIEWTABLE window only flags the observation for deletion. The observation is not physically removed from the data set; it makes the observation unusable. For more information, see Working with VIEWTABLE in SAS Language Reference: Concepts.

Comparisons

  • The FIRSTOBS= data set option overrides the FIRSTOBS= system option for the individual data set.
  • When the FIRSTOBS= data set option specifies a starting point for processing, the OBS= data set option specifies an ending point. The two options are often used together to define a range of observations to be processed.
  • When external files are read, the FIRSTOBS= option in the INFILE statement specifies which record to read first.

Example: Using the FIRSTOBS= Data Set Option

This PROC step prints the data set STUDY, beginning with observation 20:
 
proc print data=study(firstobs=20);
run;
This SET statement uses FIRSTOBS= and OBS= to read only observations 5 through 10 from the data set STUDY. The data set NEW contains six observations.
data new;
  set study(firstobs=5 obs=10);
run;
proc print data=new;
 run;

See Also

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