楼主: jjjn511
2477 6

[原创博文] 一行同属性数据变为多行 [推广有奖]

  • 0关注
  • 0粉丝

已卖:1份资源

硕士生

54%

还不是VIP/贵宾

-

威望
0
论坛币
197 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1021 点
帖子
25
精华
0
在线时间
324 小时
注册时间
2009-7-15
最后登录
2016-6-3

楼主
jjjn511 发表于 2011-9-22 18:48:40 |AI写论文
20论坛币
sas数据表如下:

              id          citing_1            citing_2           citing_3
              1             11                     12                     13
              2             21                     22                     23


想变成如下格式:

              id              citing
              1                 11
              1                 12
              1                 13
              2                 21
              2                 22
              2                 23

请教大侠给编个程呗!

最佳答案

yugao1986 查看完整内容

data test; input id $ citing_1 citing_2 citing_3; cards; 1 11 12 13 2 21 22 23 ; proc transpose data=test out=new(drop=_: rename=(col1=citing)); by id; var citing_:; run;
关键词:citing citi CIT Tin ING 数据表

沙发
yugao1986 发表于 2011-9-22 18:48:41
data test;
input id $  citing_1  citing_2  citing_3;
cards;
1 11 12 13
2 21 22 23
;
proc transpose data=test out=new(drop=_: rename=(col1=citing));
   by id;
   var citing_:;
run;
三人行必有我师

藤椅
lchw001 发表于 2011-9-23 06:05:29
If the name of the variables are not in a consequential way, you can use the following syntax:
data test;
input id $  citing_1  citing2a  citing2b;
cards;
1 11 12 13
2 21 22 23
;
proc sql;
select id, citing_1 from work.test
union all
select id, citing2a from work.test
union all
select id, citing2b from work.test;

板凳
jjjn511 发表于 2011-9-23 08:17:22
抱歉,再问一句哦!
如果citing_1中没有数据
例如: id     citing_1       citing_2       citing_3
          1                           12               13
          2         21               22               23
该怎么写命令啊?

报纸
pobel 在职认证  发表于 2011-9-23 08:23:20
data test;
input id $  citing_1  citing_2  citing_3;
cards;
1  . 12 13
2 21 22 23
;
proc transpose data=test out=new(drop=_: rename=(col1=citing) where=(^missing(citing)));
   by id;
   var citing_:;
run;
和谐拯救危机

地板
yongjiang2 发表于 2012-5-25 16:33:25
data a ;
input id c_1-c_3;
cards;
1 11 12 13
2 21 22 23
;
run;
data a1;
set a;
retain id;
array c_[*] c_1-c_3;
array x[*] x1-x3;
do i=1 to dim(c_);
        x[i]=c_[i];
        citing=x[i];
output;
end;
run;

7
yongjiang2 发表于 2012-5-25 16:41:20
data a ;
input id$ c f b;
cards;
1 11 12 13
2 21 22 23
;
run;
data a12(keep=id citing);
set a;
retain id;
array c_[*] _numeric_;
array x[*] x1-x3;
do i=1 to dim(c_);
        x[i]=c_[i];
        citing=x[i];
output;
end;
run;

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-4 11:52