SAS 在 SAS 数据步骤中连接 [英] SAS concatenate in SAS Data Step

查看:52
本文介绍了SAS 在 SAS 数据步骤中连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何描述这个问题,但这里有一个例子.我有一个初始数据集如下所示:

I don't know how to describe this question but here is an example. I have an initial dataset looks like this:

input  first second $3.;
cards;
1 A
1 B
1 C
1 D
2 E
2 F
3 S
3 A
4 C
5 Y
6 II
6 UU
6 OO
6 N
7 G
7 H
...
;

我想要这样的输出数据集:

I want an output dataset like this:

input  first second $;
cards;
1 "A,B,C,D"
2 "E,F"
3 "S,A"
4 "C"
5 "Y"
6 "II,UU,OO,N"
7 "G,H"
...
;

两个表都有两列.first"列的范围的唯一值可以是 1 到任意数字.

Both tables will have two columns. Unique value of range of the column "first" could be 1 to any number.

有人可以帮我吗?

推荐答案

类似下面的内容

 proc sort data=have;
 by first second;
 run;
data want(rename=(b=second));
 length new_second $50.;
do until(last.first);
set have;
by first second ;
new_second =catx(',', new_second, second);
b=quote(strip(new_second));
end;
drop second new_second;
run;

输出是

 first  second
 1         "A,B,C,D"
 2         "E,F"
 3          "A,S"
 4           "C"
 5          "Y"
 6         "II,N,OO,UU"
 7         "G,H"

这篇关于SAS 在 SAS 数据步骤中连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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