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
Used by: STARTOBS= data set option
Default: the last observation in the data set
Restrictions: use ENDOBS= with input data sets only

cannot be used with OBS= system and data set option or FIRSTOBS= system and 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, except when it is specified in a WHERE expression.

Using ENDOBS= in 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.

Examples

Example 1: ENDOBS= with SPD Engine

A data set is created and processed by the SPD Engine with ENDOBS=5 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 'c:\SchoolAge';
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;
The output is shown:
Four Observations Printed
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 'c:\SchoolAge';
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;
Five Observations Printed
Five Observations Printed