问题
I want to reshape data columns to rows
Initial Table as shown below
ID1 ID2 ID3 Name
----------------------------
I001 I002 I003 John
Desire Table like
ID Name
------------
I001 John
I002 John
I003 John
Can anyone help out?
Thanks lots!!
回答1:
One way to do this is to set up an array of IDs and loop through with an explicit OUTPUT statement.
data want;
set have;
array ids(3) id1-id3;
do i=1 to dim(ids);
ID=ids(i);
OUTPUT;
end;
run;
回答2:
You can use PROC TRANSPOSE
Make sure your data is sorted by NAME
proc transpose data=have out=want(rename=(_name_=ID));
by Name;
run;
来源:https://stackoverflow.com/questions/35631395/how-to-reshape-data-wide-to-long