user1481397
user1481397

Reputation: 433

SAS, transpose a table

I want to transform my SAS table from data Have to data want. I feel I need to use Proc transpose but could not figure it out how to do it.

data Have;
 input Stat$ variable_1 variable_2 variable_3 variable_4;
 datalines;
 MAX 6 7 11 23
 MIN 0 1 3  5
 SUM 29 87 30 100
;




data Want;
 input Variable $11.0 MAX MIN SUM;
 datalines;
 Variable_1 6 0 29  
 Variable_2 7 1 87
 Variable_3 11 3 87 
 Variable_4 23 5 100
;

Upvotes: 1

Views: 248

Answers (1)

Rhythm
Rhythm

Reputation: 682

You are right, proc transpose is the solution

data Have;
 input Stat$ variable_1 variable_2 variable_3 variable_4;
 datalines;
 MAX 6 7 11 23
 MIN 0 1 3  5
 SUM 29 87 30 100
;    

/*sort it by the stat var*/
proc sort data=Have; by Stat; run;

/*id statement will keep the column names*/
proc transpose data=have out=want name=Variable;
id stat;
run;

proc print data=want; run;

Upvotes: 1

Related Questions