Working with subsets created from an existing SAS data set can make more efficient use of computer resources than working with the original, larger data set. Reading fewer observations means that fewer iterations of the DATA step must occur.
- The SET statement's FIRSTOBS= option tells SAS to begin reading the data from the input SAS data set at the line number specified by FIRSTOBS.
- The SET statement's OBS= option tells SAS to stop reading the data from the input SAS data set at the line number specified by OBS.
We'll start by using the OBS= option to create the data set that we'll be working with throughout this lesson. The data set we'll use contains demographic (or "background") information collected on 638 subjects once enrolled in the National Institute of Health's Interstitial Cystitis Data Base (ICDB) Study. Not surprisingly, the ICDB Study collected data on people who were diagnosed as having interstitial cystitis! The primary reason for conducting the study was that interstitial cystitis is a poorly understood condition that causes severe bladder and pelvic pain, urinary frequency, and painful urination in the absence of any identifiable cause. Although the disease is more prevalent in women, it affects both men and women of all ages. (If you want to learn more about the ICDB Study, I refer you to one of the National Institute of Health's websites in which a general description is given and the database documentation.
Given that we'll use the ICDB Study's background data, it would probably be helpful for you to take a peek at the background data form on which the data were collected. In order to run the SAS programs in this lesson, you'll need to download and save the background data set (right-click to save!) in a folder on your computer.
Example 14.1 Section
The DATA step in the following program uses the OBS= option to tell SAS to create a temporary data set called back by selecting the first 25 observations from the permanent background data set icdb.back:
OPTIONS PS=58 LS=80 NODATE NONUMBER;
set icdb.back (obs=25);
PROC PRINT data=back;
title 'A Subset of the Background Data Set';
The program is pretty straightforward. The main thing to keep in mind is that you have to enclose the OBS= option in parentheses.
If you haven't already done so, download and save the background data set (click to save!) to a convenient location on your computer. Then, launch the SAS program, and edit the LIBNAME statement so that it reflects the location in which you've saved the data set. Then, run the SAS program, and review the output from the PRINT procedure to familiarize yourself with the data set.
Example 14.2 Section
The following program uses the SET statement's FIRSTOBS= and OBS= options to tell SAS to include fourteen observations — observations 7, 8, 9, ..., and 20 — from the permanent icdb.back data set in the temporary back data set:
LIBNAME icdb 'C:\yourdrivename\Stat481WC\02datastep\sasndata';
set icdb.back (FIRSTOBS=7 OBS=20);
PROC PRINT data=back1;
title 'Output Dataset: BACK1';
Launch the SAS program, and edit the LIBNAME statement so that it reflects the location in which you saved the background data set. Then, run the SAS program, and review the output from the PRINT procedure. Compare the output to the output of that from the previous example to convince yourself that the temporary data set back1 indeed contains fourteen observations — observations 7, 8, ..., 20 in the original background data set.