To View the Contents of SAS Libraries or SAS Files – use CONTENTS Procedure.
CONTENTS Procedure for Libraries – In SAS University Edition, SASHELP Library exists by default. Shown below is a basic PROC CONTENTS step, where, _ALL_ requests a listing of all files in the sashelp library. We used a period (.) to append _ALL_ to the library. NODS or NODETAILS restricts the printing of detailed information about each file.
CONTENTS Procedure for Files – is used to descriptor information for a data set. In the following example we will view descriptor information for BMT data set in SASHELP Library:
We can also use DATASETS Procedure with CONTENTS Statement to view the contents of a SAS library or a SAS data set. In the following example, CONTENTS statement lists the contents data sets in sashelp library and prints its directory.
In the following example, CONTENTS describes the contents of BMT data set and displays an alphabetic list of the variables in the data set.
Both PROC CONTENTS and PROC DATASETS, by default, list variables alphabetically. We can specify the VARNUM option in PROC CONTENTS or in the CONTENTS statement in PROC DATASETS to list variable names in their original order in the data set.
List of Variable names listed with VARNUM option:Major difference between CONTENTS Procedure and DATASETS Procedure with CONTENTS Statement:
PROC DATASETS uses several other statements in addition to the CONTENTS statement. These statements enable us to perform tasks that PROC CONTENTS does not perform.