I have created a sas code which generates many sas datasets. Now I want to append all of them to a single excel file . So first I want to convert all the column headers of sas datasets as first observation. Then leave space between these datasets (adding a blank observation). How can we do it?
How to change the column headers of a sas dataset into an observation?
2.1k views Asked by Abdul Shiyas At
3
one way to do this would be to use
dictionary.columns
Read through the table and check what attributes you are interested in. For your case you might be interested in the column
"NAME"
<- consist of the name of all columns.Modify the table by adding
where
statement to theproc sql
based on the identity of the column ( from which library / what type of file / name of file) e.g.where upcase(libname)= "WORK"
Then I would proceed with data step. You could use macro variable to store the value of column's names by
select variable into :
but anyhow you still need to hardcode the size for the arrayn
or any other method that store value into one observation . Also remember define the length and the type of array accordingly. You can give name to the variable in the result datasetAttribute
by addingvar1-varn
after thelength
atarray
statement.For simplicity I use
set
statement to read observation one and one and store the value of columnNAME
, which is the official column name derived when using dictionary.columns into the arrayNote that creating a non-temporary array would create variable(s) .
Add if you want to add the blank,
As two datasets start with different observation and column names do not duplicate within one dataset, the next row of a valid observation ( derived from the first
output
statement in the resulting dataset would be empty due tocall missing ( of _all_ ) ; output;