您是否能够帮助我为特定类型的左连接编写SAS脚本,如下所述?
我正在寻求表格A到表B的左连接[在下面给出],其中所有识别字段或部分匹配[至少1个字段]与表B中的其余字段完全匹配 - 缺少B / null也被视为缺失;但是,表格中填充的至少一个字段的任何部分/完全匹配 - 表格中的空白/缺失,将被视为不匹配。
以下是输入表[A和B]以及输出匹配分析/结果的示例:
表 - A
S/N COL_1 COL_2 COL_3 COL_4
-----------------------------------
1 A p ii
2 A
3 B r
表 - B
S/N COL_1 COL_2 COL_3 COL_4
-----------------------------------
1 A p ii
2 A q
3 A
4 A p 7 ii
5 B
6 B r n
输出/匹配分析
TABLE - A TABLE - B MATCH NO MATCH
----------------------------------------
1 1 Y
1 2 N
1 3 Y
1 4 N
2 1 N
2 2 N
2 3 Y
2 4 N
3 5 Y
3 6 N
答案 0 :(得分:0)
我决定不使用join,因为可以有超过4列加入......
首先, 让我们找到等于:
proc sql;
create table Equals as
select a.*,'Y' as Match, '' as No_Match from table_a as a
intersect
select b.*,'Y' as Match, '' as No_Match from table_b as b ;
quit;
现在,让我们不等于:
proc sql;
create table Not_Equals as
select a.*,'' as Match, 'N' as No_Match from table_a as a
except
select b.*,'' as Match, 'N' as No_Match from table_b as b
union
select b.*,'' as Match, 'N' as No_Match from table_b as b
except
select a.*,'' as Match, 'N' as No_Match from table_a as a ;
quit;
最后 - 让我们合并2个数据集:
data All;
set Equals Not_Equals;
run;