Skip to main content
v2026.11,858 entries · CC-BY 4.0

PROC CONTENTS in SAS: Syntax, Options and Output

PROC CONTENTS in SAS: syntax, the DATA=, OUT=, VARNUM and NODS options, and how it differs from the CONTENTS statement in PROC DATASETS.

Written and maintained by CASRAI Editorial Board

Last updated

PROC CONTENTS in SAS shows the contents of a SAS data set and prints the directory of a SAS library: the variables, their attributes and how the data set is stored, without reading a single observation. This guide covers the syntax, the options that change what is printed, how to save the metadata as a data set with OUT=, and the differences between PROC CONTENTS and the CONTENTS statement in PROC DATASETS that catch people out. Statements below come from the SAS Base Procedures Guide (checked 2026-10-29); the SAS version you run may differ in details, so treat the documentation for your installation as the final word.

What PROC CONTENTS is used for in research

SAS describes the procedure in one line: it “shows the contents of a SAS data set and prints the directory of the SAS library.” In research data work that makes it the first thing to run on a file you did not create: a survey export, a data set handed over by a collaborator, or the output of a restructuring step such as PROC TRANSPOSE. It tells you which variables exist and how they are defined before you analyse anything, and it is a quick way to produce the raw material for a data dictionary. Documenting variables this way supports the habits described in tidy data rules for structuring research data.

The SAS documentation states an important consequence of how it works: “You cannot use the WHERE option to affect the output because PROC CONTENTS does not process any observations.”

Install or access (official source only)

PROC CONTENTS is a Base SAS procedure, documented in the Base SAS Procedures Guide. SAS software is supplied by SAS Institute; start from sas.com. The official reference for every statement and option is the SAS documentation at documentation.sas.com; the older Base SAS procedures guide pages cited here remain available at support.sas.com.

Step-by-step: describing a data set and a library

1. Know the statement

The syntax summary in the SAS documentation is:

PROC CONTENTS <option-1 <...option-n>>;

The options are all written on the PROC CONTENTS statement itself. The ones you will use most are listed below, with the SAS description of each.

Option What it does (SAS documentation)
DATA= Specifies the input data set
OUT= Specifies the name for an output data set
OUT2= Names the output data set that contains information about indexes and integrity constraints
DETAILS | NODETAILS Includes in the output information about the number of observations, number of variables, number of indexes and data set labels
DIRECTORY Prints a list of the SAS files in the SAS library
NODS Suppresses the printing of individual files
NOPRINT Suppresses the printing of the output
MEMTYPE= Restricts processing to one or more types of SAS files
ORDER= Prints a list of variables in various orders
VARNUM Prints a list of the variables by their position in the data set
SHORT Prints abbreviated output
FMTLEN Prints the length of a variable’s informat or format
CENTILES Prints centiles information for indexed variables

2. Describe one data set

Name the data set with DATA=. If you leave DATA= out, the default is the most recently created data set in your job or session, so name it explicitly. In the example, mylib.survey stands for your own library and data set.

proc contents data=mylib.survey;
run;

3. List the variables in data set order

By default the variables are listed alphabetically. Add VARNUM to list them by their position in the data set instead, which is usually the order you want when reading a questionnaire file. The physical position of a variable is engine-dependent, so VARNUM reports the logical position.

proc contents data=mylib.survey varnum;
run;

ORDER= gives four alternatives: COLLATE (alphabetical, uppercase names first and then lowercase), CASECOLLATE (alphabetical even with mixed-case names and numerics), IGNORECASE (alphabetical, ignoring case) and VARNUM (the same as the VARNUM option).

4. List every data set in a library

With the _ALL_ keyword in DATA=, the procedure describes all the data sets in a library, and the SAS directory of the library is printed automatically. Add NODS to print only the directory and suppress the contents of the individual files. NODS cannot be used when DATA= names a single data set.

proc contents data=mylib._all_ nods;
run;

MEMTYPE= narrows the member types processed. For the CONTENTS statement the documented default is DATA, and output is produced only for the member types DATA, VIEW and ALL. Using _ALL_ requires read access to every read-protected data set in the library.

5. Save the metadata as a data set

OUT= writes the variable-level information to a SAS data set you can sort, filter, merge or export, for example as the skeleton of a data dictionary. OUT= does not suppress the printed output; add NOPRINT if you only want the data set.

proc contents data=mylib.survey out=work.survey_vars noprint;
run;

ORDER= and VARNUM change only the printed listing: the SAS documentation notes that “the ORDER= option does not affect the order of the OUT= and OUT2= data sets.” If you need the variables in column order in the saved data set, sort it yourself afterwards.

Output and how to read it

Without options, the printed output describes the data set and then lists its variables. Variables are listed alphabetically by default, except that numbered range lists such as x1-x100 are printed in incrementing order. Use DETAILS to include the number of observations, number of variables, number of indexes and data set labels. Use SHORT when you only need the variable names, the index information and the sort information; for a data set with more than 32,767 characters of variable names, SAS truncates the list and writes a warning to the log, and an alphabetical listing gives the complete list. Use FMTLEN to see the length of a variable’s informat or format, and OUT2= for index and integrity-constraint details.

Troubleshooting

WHERE does not filter the output

PROC CONTENTS does not process any observations, so a WHERE option has nothing to act on. To describe only some variables, create a trimmed data set first (with KEEP= or DROP= in a data step) and run PROC CONTENTS on that.

The wrong data set is described, or a library is not found

The default libref for DATA= in PROC CONTENTS is WORK. If you write data=survey without a libref, SAS looks in WORK, not in your permanent library, so always write the two-level name (library.data-set). The CONTENTS statement in PROC DATASETS behaves differently, as the next section shows.

_ALL_ prints more than you wanted

Combine _ALL_ with NODS for a directory only, or add NOPRINT with OUT= to capture the information without printing it.

Variables appear in the wrong order in the saved data set

See step 5: ORDER= does not change the order of OUT= and OUT2=.

PROC CONTENTS versus the CONTENTS statement in PROC DATASETS

The two are nearly identical; SAS documents PROC CONTENTS as working much like the CONTENTS statement in the DATASETS procedure. The documented differences are small but matter in practice.

Point PROC CONTENTS CONTENTS statement in PROC DATASETS
Default libref for DATA= WORK The libref of the procedure input library
Sequential files Can read them Cannot

The statement version is useful when you are already inside a PROC DATASETS step working on one library. For a one-off look at a data set, PROC CONTENTS is the shorter way. The same pattern appears across SAS analysis procedures, such as the models covered in ANOVA in SAS, where checking variable types and lengths first prevents most errors. If you are comparing packages, the equivalent data-description step in SPSS is covered in SPSS statistical analysis software.

FAQ

What does PROC CONTENTS do in SAS?

It shows the contents of a SAS data set and prints the directory of the SAS library: variables, their attributes and the data set description, without processing any observations.

How do I get the list of variables in the order they appear in the data set?

Add the VARNUM option (or ORDER=VARNUM) to the PROC CONTENTS statement. By default the variables are listed alphabetically.

How do I list all the data sets in a library with SAS proc contents?

Use data=libref._all_ with the NODS option to print only the library directory, or without NODS to describe every data set as well.

How do I save the PROC CONTENTS output as a data set?

Use OUT=data-set-name. Add NOPRINT if you do not also want the printed output. OUT2= does the same for index and integrity-constraint information.

Why does a WHERE option not change the PROC CONTENTS output?

Because PROC CONTENTS does not process any observations, so a WHERE option cannot affect what it prints.

Sources (official documentation)

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about PROC CONTENTS in SAS: Syntax, Options and Output

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.