ENDOBS= Data Set Option

Specifies the end observation number in a user-defined range of observations to be processed.

Valid in: DATA step and PROC step
Default: The last observation in the data set
Restrictions: Use ENDOBS= with input data sets only
Cannot be used with the OBS= system or data set option or the FIRSTOBS= system and data set option
Interactions: ENDOBS= LIBNAME Statement Option
STARTOBS= LIBNAME Statement Option
STARTOBS= Data Set Option
Engine: SPD Engine only

Syntax

ENDOBS=n

Required Argument

n

is the number of the end observation.

Details

Specifying a Range of Observations

By default, the SPD Engine processes all of the observations in the entire data set unless you specify a range of observations with the STARTOBS= or ENDOBS= options. If the STARTOBS= option is used without the ENDOBS= option, the implied value of ENDOBS= is the end of the data set. When both options are used together, the value of ENDOBS= must be greater than the value of STARTOBS=.
The ENDOBS= data set option in the SPD Engine works the same way as the OBS= data set option in the default Base SAS engine. The only difference is when ENDOBS= is specified in a WHERE expression.

Using ENDOBS= with a WHERE Expression

When ENDOBS= is used in a WHERE expression, the ENDOBS= value represents the last observation to process, rather than the number of observations to return. The following examples show the difference.
Note: The OBS= system option and the OBS= data set option cannot be used with STARTOBS= or ENDOBS= data set or LIBNAME options.

Comparisons

The ENDOBS= data set option overrides the ENDOBS= LIBNAME statement option.

Examples

Example 1: Using the ENDOBS= Data Set Option

A data set is created and processed by the SPD Engine with ENDOBS=5 option specified. The WHERE expression is applied to the data set ending with observation number 5. The PRINT procedure prints four observations, which are the observations qualified by the WHERE expression.
libname growth spde 'SAS-library';
data growth.teens;
   input Name $ Sex $ Age Height Weight;
   list;
datalines;
Alfred M 14 69.0 112.5
Carol F 14 62.8 102.5
James M 13 57.3 83.0
Janet F 15 62.5 112.5
Judy F 14 64.3 90.0
Philip M 16 72.0 150.0
Zeke M 14 71.1 105.0
Alice F 14 65.1 91.0
William M 15 66.5 112.0
;
proc print data=growth.teens (endobs=5);
   where age >13;
   title 'WHERE age > 13 using SPD Engine';
run;
ENDOBS=
Four Observations Printed

Example 2: OBS= with SPD Engine

The same data set is processed with OBS=5 specified. PROC PRINT prints five observations, which are all of the observations qualified by the WHERE expression, ending with the fifth qualified observation.
libname growth spde 'SAS-library';
data growth.teens;
   input Name $ Sex $ Age Height Weight;
   list;
datalines;
Alfred M 14 69.0 112.5
Carol F 14 62.8 102.5
James M 13 57.3 83.0
Janet F 15 62.5 112.5
Judy F 14 64.3 90.0
Philip M 16 72.0 150.0
Zeke M 14 71.1 105.1
Alice F 14 65.1 91.0
William M 15 66.5 112.0
;
proc print data=growth.teens (obs=5);
   where age >13;
   title 'WHERE age > 13 using V9';
run;
OBS=
Five Observations Printed