The example creates a dummy 'group' data set in a 'health' library to ensure its autonomy, before describing its content.
1 Code Block
PROC DATASETS / DATA STEP Data
Explanation : This example first configures system options for page and line size, suppresses the date, and sets the initial page number. It then defines a LIBNAME 'health' and creates a dummy 'group' data set with inline data to ensure the example's autonomy. PROC DATASETS is called with the NOLIST option to suppress the display of the library directory. The CONTENTS statement is used to describe the 'group' data set, with the (read=green) option which allows data to be read, and the output is saved to the 'grpout' data set. A title is also specified for the output.
Copied!
options pagesize=40 linesize=80 nodate pageno=1;
LIBNAME health 'SAS-library';
* Create a dummy 'group' data set for autonomy;
data health.group;
input ID Name $ Score;
datalines;
101 Alice 85
102 Bob 92
103 Charlie 78
;
run;
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
5
* Create a dummy 'group' data set for autonomy;
6
DATA health.group;
7
INPUT ID Name $ Score;
8
DATALINES;
9
101 Alice 85
10
102 Bob 92
11
103 Charlie 78
12
;
13
RUN;
14
15
PROC DATASETS library=health nolist;
16
contents DATA=group (read=green) out=grpout;
17
title 'The Contents of the GROUP Data Set';
18
RUN;
19
QUIT;
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.
« While PROC CONTENTS is a common choice for quick inspections, using PROC DATASETS with the CONTENTS statement is the preferred "expert" approach for managing SAS libraries. It is more efficient because it allows you to manage, rename, and describe multiple files within a single step without closing and reopening the library.
When using this method, always include the OUT= option as shown in your code. This transforms the visual report into a structured SAS data set, allowing you to programmatically validate variable types or lengths before running complex transformations. Additionally, using the NOLIST option is a best practice in production environments to suppress unnecessary output and improve processing speed. »
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.