如何基于sas中的列合并表

时间:2018-03-01 10:01:36

标签: sql sas

我在SAS中有多个表,我想将这些表合并为

table_1
obj_Id | value_txt
 1     |    T1
 2     |    T1
 3     |    T1

table_2
obj_Id | value_txt
 1     |    T2
 2     |    T2
 3     |    T2

table_3
obj_Id | value_txt
 1     |    T3
 2     |    T3
 3     |    T3

将它们合并为一个我可以做的事情

proc sql noprint;
create table merge as
select t1.obj_id, t1.value_txt as T1, t2.value_txt as T2, t3.value_txt as T3 
from table_1 t1, table_2 t2, table_3 t3,
where t1.obj_id eq t2.obj_id
and   t1.obj_id eq t3.obj_id;
quit;

但在我的实际情况中,我在15-20附近的表中每个表中的记录超过5K,因此这种方法变得非常慢并且需要5-7分钟来处理。

我正在寻找任何更好,更快捷的方法将表合并为一个表作为一个表。

1 个答案:

答案 0 :(得分:0)

下面的SAS SQL和Merge代码都会创建相同的输出:

/*SAS Inner Join*/
proc sql noprint;
create table merge as select 
t1.obj_id , t1.value_txt as T1, t2.value_txt as T2, t3.value_txt as T3 
from 
table_1 t1 inner join table_2 t2 on  t1.obj_id = t2.obj_id 
inner join  table_3 t3 on t1.obj_id = t3.obj_id;
quit;
/*SAS Data Step Megrge*/
data merge_sas;
 merge table_1(rename=(value_txt=T1)) table_2(rename=(value_txt=T2)) table_3(rename=(value_txt=T3));
 by obj_id;
 run;

输出:

Merge Table