如何将数据从宽到长重塑 [英] How to reshape data wide to long

查看:32
本文介绍了如何将数据从宽到长重塑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据列重塑为行

初始表格如下图

ID1     ID2     ID3     Name
----------------------------
I001    I002    I003    John

Desire Table like

Desire Table like

ID      Name
------------
I001    John
I002    John
I003    John

有人可以帮忙吗?

非常感谢!!

推荐答案

一种方法是设置一个 ID 数组并使用显式 OUTPUT 语句进行循环.

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;

这篇关于如何将数据从宽到长重塑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆