Currently, My data is like:
A | B | C | D |
Name | Sex | Address | Phone |
Rachel | F | 789 Mid County | 111-111-1111 |
My first observation is my variable name. therefore, I want my data to look like:
Name | Sex | Address | Phone |
Rachel | F | 789 Mid County | 111-111-1111 |
Please help!
Is current sas dataset?
excel or some other like csv?
Yes it is SAS dataset.
Sorry to say that is a poor data table. Looks like the solution should have been handled during the creating of the original table. Why would anyone create a table in that manner in SAS.
Well done, i think your approach is pretty sound!
So you have a sas dataset with (1) var names of A, B, C, ..., (2) the intended var names are actually the values of A, B, C, ... in the first row. Looks like it was once a spreadsheet.
Is the spreadsheet still available? If so, use proc import.
data have;
input A $6. +1 B $3. +1 C $14. +1 D $12.;
datalines;
Name Sex Address Phone
Rachel F 789 Mid County 111-111-1111
run;
filename renames temp ;
data _null_;
set have (obs=1);
file renames;
put 'rename '
/ (_all_) (=)
/ ';'
;
run;
data want;
set have (firstobs=2);
%include renames ;
run;
Outdated reply but may help someone in future
/*----------------------------------------*/
data test;
infile datalines;
input A : $10. B : $3. C & $20. D : $20.;
datalines;
Name Sex Address Phone
Rachel F 789 Mid County 111-111-1111
;
run;
proc transpose data=test out=testt;
var A B C D;
run;
proc transpose data=testt out=testtt(drop=_:);
var col2;
id col1;
run;
/*----------------------------------------*/
The double proc transpose is nice in that it has a simple structure, and it uses a pre-packaged sas routine.
But it may not scale well. Transposing 1,000,000 observations will create a dataset with 1,000,000 variables in the intermediate data set TEST1. The entire dataset would have to be processed two times, which can begin to use significant resources.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.