Personal tools
You are here: Home Software Packages SAS Limiting observations

Limiting observations

You can control how many records you process or print when testing your programs

If you just want to print a few observations in a data set or test a new program it is a good idea to limit the observations (records) processed in your program. There is no reason to test your program on all 100,000 records if you just want to see if your calculation works or if you can read a raw data file. Limiting observations by using the OBS and FIRSTOBS options can significantly reduce processing time and paper usage.

Limiting observations when printing:

libname sastmp '/sastmp';
proc print data=sastmp.class (obs=50);

The (obs=50) option will limit the printing to the first 50 observations in the data set. OBS specifies the last observation of the SAS data set that will be printed. It does NOT specify how many observations that should be printed. If you wanted to begin printing at the 20th observation and end at the 50th observation you can use the firstobs option:

 proc print data=sastmp.class (firstobs = 20 obs = 50);

Limiting observations in a data set;

libname sastmp '/sastmp';
data data1;
set sastmp.class (obs=50);
--rest of program here--

This will limit processing to the first 50 observations in sastmp.class. You can also use the firstobs option to begin processing at a place other than the first observation. If you combine firstobs with the obs option, remember that obs tells SAS the LAST observation to process not how many observations to process so be sure that obs is greater than firstobs (firstobs = 1000 obs = 1500).

Limiting observations in a procedure (proc) step

libname sastmp '/sastmp';
proc freq data=sastmp.class (obs=30);

Limiting observations when reading raw data into a SAS data set

libname sastmp '/sastmp';
filename tech '/home/info/flatfile';

data sastmp.newfile;
infile tech obs=30;

@1 idnum 6.
@7 level 1.
@8 state $2.
@10 county $3.

This program will read the first 30 records from the "flatfile" tech into the SAS data set.

Document Actions

Copyright ©2014, The Pennsylvania State University | Privacy and Legal Statements
Contact the Help Site Administrator | Last modified Aug 13, 2008 | Weblion Partner