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 variableN
option in PROC MEANS
or PROC FREQ
NOOBS
option inPROC PRINT
OBS=
system option_N_
automatic variableN
option inPROC MEANS
orPROC 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;
OBS=
System Option
The OBS=
option limits the number of observations that SAS reads from a dataset.
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;
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;
Summary Table
Feature | Usage | Purpose |
---|---|---|
NOOBS | In PROC PRINT | Hide observation numbers in output |
OBS= | Global system option | Limit records read from datasets |
_N_ | In DATA steps | Count iteration, control row logic |
N | In summary procedures | Display 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.
0 Comments
If you have any doubt please comment or write us to - datahark12@gmail.com