CONTENTS Function

CONTENTS (<libref> <, SAS-data-set> ) ;

The CONTENTS function returns a column vector that contains the variable names for a SAS data set. The vector contains $n$ rows, where $n$ is the number of variables in the data set. The variable list is returned in the order in which the variables occur in the data set.

You can specify the SAS data set with a one-level name (for example, A) or with a libref and a SAS data set name (for example, Sashelp.Class). If you specify a one-level name, SAS/IML software uses the default SAS data library (as specified in the DEFLIB= option in the RESET statement.) If no arguments are specified, the current open input data set is used.

The following statements use the CONTENTS function to obtain the names of variables in SAS data sets:

x = 1:5;
create temp from x;
append from x;
tempVars = contents();            /* use current open input data set */
close temp;

classVars = contents("Sashelp", "Class"); /* contents of data set in */
                                          /* Sashelp library         */
print tempVars classVars;

Figure 24.77: Names of Variables in SAS Data Sets

tempVars classVars
COL1 Name
COL2 Sex
COL3 Age
COL4 Height
COL5 Weight


See also the description of the SHOW CONTENTS statement.