20.2 C
London
Sunday, June 22, 2025
HomeSASDescriptive Statistics in SASHow to Use Proc Contents in SAS (With Examples)

How to Use Proc Contents in SAS (With Examples)

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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;
    datalines;
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
;
run;

/*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:

Conclusion

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

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories