data have; length a $25 b $4 c $8 d $8 ; input a b c d ; datalines; dept month_ count_ status Acct JAN20 1 0 Eng FEB20 1 1 Sales FEB20 1 1 ; run;
a | b | c | d | |
dept | mont | count_ | status | |
Acct | JAN2 | 1 | 0 | |
Eng | FEB2 | 1 | 1 | |
Sales | FEB2 | 1 | 1 | |
Desire is replace row 1 and make them the header | ||||
dept | mont | count_ | status | |
Acct | JAN2 | 1 | 0 | |
Eng | FEB2 | 1 | 1 | |
Sales | FEB2 | 1 | 1 |
I tried
data have2 (firstobs=2);
set have;
;
run;
Good start, although I would put the FIRSTOBS= dataset option on the INPUT dataset and not the OUTPUT dataset.
You also want to use the first row to RENAME the variables.
Here is an easy method using PROC TRANSPOSE.
proc transpose data=have(obs=1) out=names ;
var _all_;
run;
proc sql noprint;
select catx('=',nliteral(_name_),nliteral(col1))
into :renames separated by ' '
from names
where upcase(_name_) ne upcase(col1)
;
quit;
data want;
set have (firstobs=2);
rename &renames;
run;
So your dataset is not named DATA. Use the actual name of your existing dataset.
Also either your first step excluded the SEPARATED BY ' ' clause or your dataset only had one variable.
If you also want to change the variables that look like numbers into numeric variables then you might be able to let PROC IMPORT help you.
filename csv temp;
data _null_;
set have ;
file csv dsd ;
put (_all_) (+0);
run;
proc import datafile=csv dbms=csv out=want replace ;
guessingrows=max;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.