SAS PROC CONTENTS: Learn with Examples

Deepanshu Bhalla Add Comment

In this tutorial, we will cover how to use PROC CONTENTS in SAS, along with examples.

What does PROC CONTENTS do?

The PROC CONTENTS procedure provides a summary of a dataset's contents, including details such as variable names, types, and attributes (such as formats, informats, and labels). It also tells you the number of observations and variables present in the dataset, as well as the creation date of the dataset.

Below is the syntax for PROC CONTENTS

PROC CONTENTS DATA= dataset_name;
RUN;

Here, we are using the built-in SAS dataset named CARS from the SASHELP library. Our goal is to explore this dataset using the PROC CONTENTS procedure.

PROC CONTENTS DATA = SASHELP.CARS;
RUN;
Output
SAS: PROC CONTENTS

1 Observations : The number of rows in the dataset. The dataset "CARS" from the SASHELP library contains 428 observations.

2 Variables : The number of columns in the dataset. The dataset "CARS" from the SASHELP library contains 15 variables.

3 Created : The dataset's creation date and time.

Variables Summary

Here is the summary of variables in the dataset provided by PROC CONTENTS.

PROC CONTENTS: Variables Format
  1. #: Represents the original order of the variable in the dataset. PROC CONTENTS displays variables in alphabetical order by name, rather than their original order of appearance in the dataset.
  2. Type: Indicates whether the variable is numeric (Num) or character (Char).
  3. Len: Refers to length of variables.
  4. Format: Displays the format applied to the variables' values when printed on the output window.
  5. Informat: Represents the format used to read the variables' data in SAS.
  6. Label: Displays the labels of variables. Please note that these are not value labels.
PROC CONTENTS: SORT
  • Sortedby: Displays the variable(s) by which the dataset is sorted.
  • Validated: It shows YES if PROC SORT/SQL sorted the dataset. Else NO.
  • Character Set: The character set used to sort the data, can be ASCII, EBCDIC, or PASCII.
VARNUM Option

By default, PROC CONTENTS lists variables in alphabetical order. However, when using the VARNUM option, SAS displays the variables in the order they appear in the dataset.

proc contents data=sashelp.cars varnum;
run;
How to display only Variable Names using PROC CONTENTS

To display only the variable names using PROC CONTENTS, you can specify the SHORT option. This option restricts the output to only the variable names.

proc contents data=sashelp.cars short varnum;
run;
How to run PROC CONTENTS on the entire library

To run PROC CONTENTS on all the datasets in a SAS library, we can use the keyword _ALL_.

proc contents data=work._all_;
run;
How to save output of PROC CONTENTS in a dataset

We can use the NOPRINT option to disable the printing of output. The OUT= option is used to create a new dataset and save the output in that dataset.

proc contents data=sashelp.cars noprint out=readin;
run;
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

Post Comment 0 Response to "SAS PROC CONTENTS: Learn with Examples"
Next → ← Prev