SAS中文论坛

标题: 请教大虾一个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 cds(drop=_name_ col1 col2);
set bds;
c=catx('',col1,col2);
run;
[/code:oye6oygp]
作者: shiyiming    时间: 2012-10-3 00:22
标题: Re: 请教大虾一个SAS字符串连接的问题
假设:
1 有些ID包含两条以上记录
2 原始数据中所有相同ID都排在一起

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;




欢迎光临 SAS中文论坛 (http://www.mysas.net/forum/) Powered by Discuz! X3.2