One easy way is to use PROC TRANSPOSE twice.
Two things you need to make sure you have.
1) A way to uniquely identify the original rows.
2) At least one character variable.
Let's make a little test dataset that has a number and a date variable.
data test ;
_row_+1;
input name :$20. age date :date9. ;
format date date9. ;
cards;
Sam 20 01JAN2018
Julie 30 30DEC2016
;
So in that dataset _ROW_ is my unique identifier. So now let's transpose it. Notice we will need to exclude _ROW_ from the resulting data. Then transpose it back.
proc transpose data=test
out=middle (where=(lowcase(_name_) ne '_row_'))
;
by _row_;
var _all_;
run;
proc transpose data=middle out=want (drop=_name_);
by _row_;
var col1 ;
run;
Let's see what happened.
proc contents data=want; run;
proc print data=want; run;
The CONTENTS Procedure
Alphabetic List of Variables and Attributes
# Variable Type Len
1 _row_ Num 8
3 age Char 20
4 date Char 20
2 name Char 20
Obs _row_ name age date
1 1 Sam 20 01JAN2018
2 2 Julie 30 30DEC2016
If you don't know if you have an id variable or a character variable then you could just create one first.
data to_transpose ;
_row_ + 1;
length _charvar_ $12 ;
set have;
run;
And then use that as the source table to start with. You can later drop the _ROW_ and _CHARVAR_ variables.
Also note that it will typically right align the converted numeric variables. If you would rather have them left aligned add a step between the proc transpose steps to modify the "middle" dataset.
data middle;
set middle;
col1=left(col1);
run;
... View more