标题: 请教大虾一个SAS字符串连接的问题 [打印本页] 作者: shiyiming 时间: 2012-9-7 15:34 标题: 请教大虾一个SAS字符串连接的问题 测试数据集如下:
data a;
input id x $3-10;
cards;
1 a b
1 b c d
2 x y
2 z
;
run;
期望得到的结果如下:
1 a b b c d
2 x y z
;
如何实现?多谢大虾救助!作者: shiyiming 时间: 2012-9-7 20:10 标题: Re: 请教大虾一个SAS字符串连接的问题 [code:oye6oygp]
data ads;
input id x $ & 5.;
cards;
1 a b
1 b c d
2 x y
2 z
;
proc transpose data=ads out=bds;
by id;
var x;
run;
data ads;
input id x $ & 5.;
cards;
1 a b
1 b c d
2 x y
2 z
2 z y d
;
run;
data outds;
length newvar $200.;
set ads;
by id notsorted;
retain newvar;
if first.id then newvar='';
newvar=strip(newvar)||' '||strip(x);
if last.id;
keep id newvar;
run;