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 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!
options pagesize=40 linesize=80 nodate pageno=1;
LIBNAME health 'SAS-library';
proc datasets library=health nolist;
contents data=group (read=green) out=grpout;
title 'The Contents of the GROUP Data Set';
run;
quit;
1
options pagesize=40 linesize=80 nodate pageno=1;
2
3
LIBNAME health 'SAS-library';
4
PROC DATASETS library=health nolist;
5
contents DATA=group (read=green) out=grpout;
6
title 'The Contents of the GROUP Data Set';
7
RUN;
8
QUIT;
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.
Notice: Undefined variable: stmtFrFallback in /var/www/app/detail_sascode.php on line 1428
Fatal error: Uncaught Error: Call to a member function execute() on null in /var/www/app/detail_sascode.php:1428
Stack trace:
#0 {main}
thrown in /var/www/app/detail_sascode.php on line 1428