How to reshape data wide to long [duplicate]

我的梦境 提交于 2019-12-11 23:35:49

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!