我有两个数据集A& B.我想在两个字段中加入它们:ID和月末日期。这在数据集A中定义为EOMDate,在数据集B中定义为BalDate。如何加入它们以使ID和日期相互匹配?
答案 0 :(得分:0)
汤姆的评论有效。以下是一些工作样本:
/*Create some input data for the samples...*/
data first;
input id_a id_b data $;
cards;
1 1 A
2 2 B
3 33 C
4 4 D
55 5 E
;
run;
data second;
input id_a id_b data2 $;
cards;
1 1 AA
2 2 BB
3 3 CC
4 4 DD
5 5 EE
;
run;
/*The proc sql way. We create table 'combo' as result. */
/*You can add more conditions than one. */
proc sql noprint;
create table combo as
select * from first join second
on first.id_a=second.id_a and first.Id_b=second.id_b;
quit;
我注意到使用大型集时proc sql非常慢。 这是一种与数据语句相同的方法。 首先,您需要对数据进行排序。
/*A way to accomplish this with datasets.*/
proc sort data=first; by id_a id_b; run;
proc sort data=second; by id_a id_b; run;
data Combo_sas;
merge first(in=a) second(in=b);
by id_a id_b;
if a and b;
run;