6
votes

I'm in a beginner SAS class and we are required to display only the section of the PROC CONTENTS output that shows the variables in the dataset. For example, when you do

proc contents data=whas.heart3;
run;

The output is 3 tables. The 3rd table is titled:

Alphabetic List of Variables and Attributes

I need to figure out how to modify the above code to display only that 3rd table.

3

3 Answers

9
votes

Out put is delivered via the Output Delivery System (ODS). Use ods trace on; and the system will tell you what is being delivered. In this case, Variables is the table you are looking for.

Use ods select Variables; to tell ODS to ONLY deliver the variables table. Then reset to default (ods select default;) for other procedures.

ods select Variables;
proc contents data=mydata;
run;
ods select default;
5
votes

I'm not sure whether ODS will be covered in a beginner's course. The other option is to check the online help for SAS procedures, here you will find that there is an option SHORT that can be used with PROC CONTENTS. This will just display the list of variables.

proc contents data=whas.heart3 short;
run;
1
votes

An alternative to using ODS is using the PROC SQL dictionary.columns. It is slower but potentially more versatile.

PROC SQL;
  SELECT varnum, name, type, length,format, informat
  FROM dictionary.columns 
  WHERE upcase(libname)="WHAS"
    AND upcase(memname)="HEART3"
  ORDER BY varnum;
QUIT;

This may be helpful when using more complicated ODS settings and is equivalent to

ODS SELECT Variables;
  PROC CONTENTS varnum data=whas.heart3; RUN;
ODS SELECT default;