Stop Scrolling the Log: How to Export SAS Metadata to a Dataset with PROC DATASETS

This code is also available in: Deutsch Español Français
Difficulty Level
Beginner
Published on :
Simon

Expert Advice

Simon
Expert SAS et fondateur.

Unlike most SAS procedures which terminate with a RUN; statement, PROC DATASETS is an interactive procedure. This means it remains active and locks the library until it encounters a QUIT; statement or a new PROC or DATA step. Always ensure you include an explicit QUIT; (as shown in your code) to release the library lock and prevent "Resource is in use" errors later in your program.

Use PROC DATASETS instead of PROC CONTENTS for cleaner logs and automated metadata capture.
The DATASETS procedure is used to manage SAS© libraries and library members. The CONTENTS statement is used to display the metadata of a SAS© data set, including variable names, types, formats, labels, and other relevant information. The NOLIST option suppresses the display of the library member list, while the OUT=grpout option creates a new data set containing the metadata of the 'group' data set.
Data Analysis

Type : CREATION_INTERNE


The example uses a data set referenced by a 'health' library. The creation of the 'group' data set is not directly provided in this example, but it is assumed to have been created in a previous example ('Modifying SAS Data Sets'). For autonomy, it would be preferable to recreate a simple data set. However, as it refers to a previous modification, it is considered part of a coherent flow of examples and does not require undefined external data.

1 Code Block
PROC DATASETS
Explanation :
This code block configures system options for display (page size, line size, date suppression, and initial page number). It then defines a SAS library named 'health'. The DATASETS procedure is called with the 'library=health' option to specify the library to manage and 'nolist' to avoid displaying the full list of library members. The CONTENTS statement is used to display information about the 'group' data set. The '(read=green)' option indicates that the 'group' data set is read-only, and 'out=grpout' creates a new data set 'grpout' which will contain the metadata of the 'group' data set.
Copied!
1options pagesize=40 linesize=80 nodate pageno=1;
2 
3LIBNAME health 'SAS-library';
4PROC DATASETS library=health nolist;
5 contents DATA=group (read=green) out=grpout;
6 title 'The Contents of the GROUP Data Set';
7RUN;
8QUIT;
Pro Tip
PROC DATASETS is the only procedure that can rename variables, delete files, or modify formats without reading and rewriting the entire data file. It modifies the header in place, making it instant even for multi-gigabyte files.
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright © SAS Institute Inc. All Rights Reserved