Published on :
Data Manipulation INTERNAL_CREATION

Example: Data Set Options

This code is also available in: Deutsch Español Français
Awaiting validation
The WHERE statement is applied first to the original input data set, then the FIRSTOBS= and OBS= options are applied to the results of the WHERE statement. This allows filtering data according to a condition first, then selecting a specific subset of observations from these filtered data. The values specified for OBS= and FIRSTOBS= are not physical observation numbers in the data set, but logical numbers in the subset resulting from the WHERE expression.
Data Analysis

Type : INTERNAL_CREATION


Examples use generated data (datalines) or SASHELP.

1 Code Block
DATA STEP / PROC PRINT Data
Explanation :
This DATA step creates a data set named 'example' with 10 observations and two variables, 'i' and 'x'. 'x' is calculated as 'i + 1'. A PROC PRINT follows to display the initial content of the data set.
Copied!
1DATA example;
2 DO i=1 to 10;
3 x=i + 1;
4 OUTPUT;
5 END;
6RUN;
7 
8PROC PRINT DATA=example; RUN;
2 Code Block
PROC PRINT
Explanation :
This PROC PRINT first applies the WHERE statement to select observations where 'i' is greater than 5 in the 'example' data set. Then, on this resulting subset (observations 6 to 10), it applies the data set options FIRSTOBS=2 and OBS=4. This means it selects logical observations 2, 3, and 4 from the filtered subset, which corresponds to observations 7, 8, and 9 from the original data set.
Copied!
1 
2PROC PRINT
3DATA=example (firstobs=2 obs=4);
4 
5where i > 5;
6RUN;
7 
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright © SAS Institute Inc. All Rights Reserved