How to read variable names in a SAS data set?

mj023119 picture mj023119 · Mar 21, 2011 · Viewed 56.2k times · Source

Are there any statements\functions capable of get the name of variables? Preferrably putting them into a column of another data set, a text field or a macro variable.

E.g.

- Data set 1

Name age sex

    Jk   14   F
    FH   34   M
  • Expected data set

    Var_name_of_dataset1

    Name
    age
    sex
    

PS: I know a statement: select into, which does sth relevantly It can read the value of a column into a field with customized separetors, and therefore wish there are similar ways of reading column names into a field or a column.

Thanks

Answer

Laurent de Walick picture Laurent de Walick · Mar 21, 2011

PROC CONTENTS would be the quickest way to get that information in a dataset. Column names can be found in the column NAME.

proc contents data=sashelp.class out=contents noprint;
run;