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
When you want to control which variables are read into the program data vector, use the data set options in the statement (such as a SET statement) that reads the SAS data set. The options are generally more efficient than using the statements.
The first option to list the column names of a SAS data set is with the PROC CONTENTS statement. With the syntax below you store the column names in a new table. If you don't specify the keep options, then the output table will contain not only the column names but also its format, its length, its type, etc.
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;
You can also use a datastep and array functions, e.g.
data colnames ; set sashelp.class (obs=1) ; array n{*} _NUMERIC_ ; array c{*} _CHARACTER_ ; do i = 1 to dim(n) ; vname = vname(n{i}) ; output ; end ; do i = 1 to dim(c) ; vname = vname(c{i}) ; output ; end ; run ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With