How to Use Proc Contents in SAS (With Examples)

You can use proc contents in SAS to print a summary of the contents of a dataset.

The following example shows how to use this procedure in practice.

Example: Using Proc Contents in SAS

Suppose we have the following dataset in SAS that contains information about various basketball players:

/*create dataset*/
data original_data;
    input team $ points rebounds;
A 12 8
A 12 8
A 12 8
A 23 9
A 20 12
A 14 7
A 14 7
B 20 2
B 20 5
B 29 4
B 14 7
B 20 2
B 20 2
B 20 5

/*view dataset*/
proc print data=original_data;

We can use proc contents to obtain a summary of the contents in the dataset:

/*view contents of dataset*/
proc contents data=original_data;

The first table in the output displays various information about the dataset but the most useful values include:

  • Data Set Name: The name of the dataset (original_data)
  • Observations: The number of rows in the dataset (14)
  • Variables: The number of columns in the dataset (3)

The second table in the output displays information about the engine and host used in SAS. In most cases, this information won’t be particularly useful to you.

The third table displays an alphabetical list of the variables in the dataset along with their data type and length.

From this table we can see:

  • points is a numeric variable
  • rebounds is a numeric variable
  • team is a character variable

If you would instead like these variables to be displayed in the order they appear in the dataset, you can use order=varnum as follows:

/*view contents of dataset and retain original order of variables*/
proc contents data=original_data order=varnum;

The third table in the output will now display a list of variables in the order in which they appear in the dataset:


In this tutorial we saw that proc contents can be used in SAS to obtain a summary of the contents of a dataset.

In particular, we saw that proc contents is useful for obtaining the following information:

  • The size of a dataset (number of columns and rows)
  • The names and data type of each variable in the dataset

In practice, we often use proc contents before performing any type of statistical analysis just to gain a better understanding of the size and structure of a dataset.

Additional Resources

The following tutorials explain how to perform other common tasks in SAS:

How to Use Proc Summary in SAS
How to Use Proc Tabulate in SAS
How to Use Proc Rank in SAS

Leave a Reply

Your email address will not be published. Required fields are marked *