Desktop productivity for business analysts and programmers

Reshape wide tables to long tables

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 81
Accepted Solution

Reshape wide tables to long tables

data have;
  input ID1 ID2 $ Value1 Value2;
  cards;
1 A 2 3
2 A 4 5
;
run;

data want;
  input ID1 ID2 $ Type $ Value;
  cards;
1 A Value1 2
1 A Value2 3
2 A Value1 4
2 A Value2 5
;
run;

Basically keep ID1 and ID2, and then reshape column 3 and column 4.

How to achieve it? Thanks!

 


Accepted Solutions
Solution
‎06-19-2017 07:01 PM
Super Contributor
Posts: 397

Re: Reshape wide tables to long tables

As Bruno says you need Proc Transpose for this but you'll also want to do some renaming e.g.

 

proc transpose data=have out=want(rename=(_name_=type col1=value));
by id1 id2;
var value1 value2;
run;

View solution in original post


All Replies
SAS Super FREQ
Posts: 706

Re: Reshape wide tables to long tables

You can use Proc TRANSPOSE to do this.

 

Use BY statement for your id vars and the VAR statement for the vars to you want to transpose.

Solution
‎06-19-2017 07:01 PM
Super Contributor
Posts: 397

Re: Reshape wide tables to long tables

As Bruno says you need Proc Transpose for this but you'll also want to do some renaming e.g.

 

proc transpose data=have out=want(rename=(_name_=type col1=value));
by id1 id2;
var value1 value2;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 152 views
  • 2 likes
  • 3 in conversation