3.1 - Viewing the Contents of SAS Libraries

Before investigating other methods for reading data into a SAS data set, let's digress for a few minutes to learn how to use the CONTENTS procedure to view the contents of SAS libraries.

The CONTENTS Procedure

The CONTENTS procedure allows us to create SAS output that describes either the contents of a SAS library or the descriptor information for an individual SAS data set. In order to view the contents of a SAS library, we can use the following general form of the procedure:

PROC CONTENTS data = libref._ALL_ NODS;
RUN;

where:

  • libref is the libref that you assigned to the library
  • the _ALL_ option requests a listing of all of the SAS files in the library
  • the NODS option (which stands for "no details") suppresses the printing of detailed information about each file when you specify the _ALL_ option.

NOTE! Two things:

  1. You need to connect the _ALL_ option to the libref with a period (.)
  2. You can specify the NODS option only when you specify the _ALL_ option. Let's take a look at an example

Example 3.1 Section

The following SAS code requests a listing of the contents of the library called sashelp:

PROC CONTENTS data = sashelp._ALL_ nods;
RUN;

First, what are SAS Libraries all about? Let's have you launch your SAS application. If the Explorer Window is not active, then click on the Explorer tab SAS left hand navigation window tab for Explorer that appears among the bottom tabs.

opened Explorer window showing Libraries, File Shortcuts, Favorite Folders, and Desktop icons

Double click Libraries, which contains all available libraries. Then you should see a listing of your libraries, that is, something that looks like this:

Active libraries window showing icons for maps, sashelp, sasuser, work etc...

You should see, at least, three libraries that SAS defines for you by default:

  • As you know, Work is a temporary library for files that do not need to be saved from session to session.
  • Sashelp is a permanent library that contains more than 200 sample data and other files that control how SAS works at your site. You can download these sample data for practicing or illustrating purposes.
  • Sasuser is a permanent library that contains SAS files in the Profile catalog that store your personal settings. You may also opt to store your own files there. (Personally, I don't.)

Now, let's have you run  the SAS code. Upon doing so, you should see an output that looks something like this:

The SAS System

The CONTENTS Procedure

Directory

Libref

SASHELP

Levels

22

Level 1

Engine

V9

Physical Name

C:\Program Files\SASHome\SASFoundation\9.4\nls\1d\SASCFG

Filename

C:\Program Files\SASHome\SASFoundation\9.4\nls\1d\SASCFG

Owner Name

BUILTIN\Administrators

File Size

4KB

File Size (bytes)

4096

Level 2

Engine

V9

Physical Name

C:\Program Files\SASHome\SASFoundation\9.4\core\sashelp

Filename

C:\Program Files\SASHome\SASFoundation\9.4\core\sashelp

Owner Name

BUILTIN\Administrators

File Size

96KB

File Size (bytes)

98304

Level 3

Engine

V9

Physical Name

C:\Program Files\SASHome\SASFoundation\9.4\aacomp\sashelp

Filename

C:\Program Files\SASHome\SASFoundation\9.4\aacomp\sashelp

Owner Name

BUILTIN\Administrators

File Size

0KB

File Size (bytes)

0

Level 4

Engine

V9

Physical Name

C:\Program Files\SASHome\SASFoundation\9.4\af\sashelp

Filename

C:\Program Files\SASHome\SASFoundation\9.4\af\sashelp

Owner Name

BUILTIN\Administrators

File Size

0KB

File Size (bytes)

0

... partial listing is below ...

#

Name

Member Type

Level

File Size

Last Modified

1

AACOMP

DATA

3

384KB

2017/11/09 01:06:28

.

AACOMP

INDEX

 

161KB

2017/11/09 01:06:28

2

AARFM

DATA

2

256KB

2017/09/06 23:57:22

.

AARFM

INDEX

 

21KB

2017/09/06 23:57:22

3

AC

CATALOG

2

17KB

2017/09/07 00:00:14

4

ADSMSG

DATA

2

256KB

2017/09/06 23:59:19

.

ADSMSG

INDEX

 

37KB

2017/09/06 23:59:19

5

AFCLASS

CATALOG

2

2MB

2017/09/07 00:02:06

6

AFMSG

DATA

2

448KB

2017/09/06 23:56:10

.

AFMSG

INDEX

 

73KB

2017/09/06 23:56:10

7

AFTOOLS

CATALOG

2

2MB

2017/09/07 00:02:06

8

AIR

DATA

11

128KB

2017/09/07 00:01:10

9

APPLIANC

DATA

11

128KB

2017/09/07 00:01:10

10

ASSCMGR

DATA

2

320KB

2017/09/07 00:08:56

11

ASSIST

CATALOG

5

9MB

2013/06/20 01:51:39

12

AUTHLIB

DATA

16

192KB

2017/09/07 00:35:07

13

BASE

CATALOG

2

681KB

2017/09/06 23:57:23

14

BASEBALL

DATA

2

192KB

2017/11/09 01:22:58

15

BEI

DATA

2

5MB

2017/11/09 01:22:59

16

BFC

CATALOG

9

513KB

2017/09/06 23:58:55

Now, to view the descriptor information for any of the files that appear in the sashelp library, we need to modify our CONTENTS procedure a little bit.

Example 3.2 Section

The following SAS code tells SAS to display the descriptor information for the class data set that appears in the sashelp library:

PROC CONTENTS data = sashelp.class;
RUN;

Launch and run  the SAS code. (If, by chance, the class data set is not stored in your sashelp library, modify the code so that it references a data set that is stored in the library.) Review the resulting output to convince yourself that SAS does indeed display the descriptor information. Note in particular that, by default, SAS displays the variable information in alphabetical order:

Alphabetic List of Variables and Attributes

#

Variable

Type

Len

3

Age

Num

8

4

Height

Num

8

1

name

Char

8

2

Sex

Char

1

5

Weight

Num

8

If we instead preferred to view a listing of the variables in the order in which they appear in the data set, we again need to modify the CONTENTS procedure a bit.

Example 3.3 Section

The following SAS code again tells SAS to display the descriptor information for the class data set that appears in the sashelp library. The varnum option requests that SAS display the listing of the variables in the order in which they appear in the data set:

PROC CONTENTS data = sashelp.class varnum;
RUN;

Launch and run  the SAS code. (Again, if the deskact data set is not stored in your sasuser library, modify the code so that it references a data set that is stored in the library.) Review the resulting output to convince yourself that SAS displays the descriptor information, and in particular, the variable information in the order in which the variables appear in the data set:

Variables in Creation Order

#

Variable

Type

Len

1

name

Char

8

2

Sex

Char

1

3

Age

Num

8

4

Height

Num

8

5

Weight

Num

8