Understanding NOOBS, OBS=, N, and N in SAS Programming

When working with datasets in SAS, it's important to control data processing and output efficiently. SAS provides several options and automatic variables that help manage how data is read, processed, and displayed. In this post, we’ll explore four commonly used features:

  • NOOBS option in PROC PRINT
  • OBS= system option
  • _N_ automatic variable
  • N option in PROC MEANS or PROC FREQ

Let’s understand each with examples.

Use of NOOBS  

It is used for Suppress column which tells the row/observation number in Proc print.

Example - See both outputs with NOOBS and without NOOBS

Proc Print Data=SASHELP.CARS;
WHERE MAKE='Audi';
RUN;

Proc Print Data=SASHELP.CARS NOOBS;
WHERE MAKE='Audi';
RUN;

Use of Noobs

OBS= System Option

The OBS= option limits the number of observations that SAS reads from a dataset.

Syntax:
options obs=5;

Example:
options obs=5;
proc print data=sashelp.class;
run;

 Use of OBS  and N options - 

OBS option give the Actual row number from the original dataset, for example in below code output, row number starts from 8 because First row of Audi car in source dataset is available at 8th position


Proc PRINT data=SASHELP.cars N OBS;
where Make='Audi';
run;

Use of OBS and N - Datahark

N Option gives the Total count of observation in dataset.

Use of _N_ 

As I already explained in  my previous post for PDV - there are two automatic variables are being created in datastep these are - _N_ and _ERROR_

_N_ counts the Number of times Datastep begin to execute.

For Example - if we want to print the top 10 rows of any dataset - 

data test;
set SASHELP.CARS;
N=_N_;
if _n_<=10;
run;

Use of _N_ = Datahark

Summary Table

FeatureUsagePurpose
NOOBSIn PROC PRINTHide observation numbers in output
OBS=Global system optionLimit records read from datasets
_N_In DATA stepsCount iteration, control row logic
NIn summary proceduresDisplay count of non-missing values

Final Thoughts

These options and variables are small but powerful tools in a SAS programmer’s toolkit. Whether you're generating cleaner reports with NOOBS, testing code with OBS=, controlling logic with _N_, or summarizing data using N, understanding their usage can significantly enhance your efficiency in SAS.

Post a Comment

0 Comments