如何使用SAS比较2个表中的2列
how to compare 2 columns in 2 tables using SAS
在 2 tables a1, a2 中有 2 个相似的列(x1 vs x2)。我怎样才能匹配和排列它们?
我尝试了比较功能,但失败了。
data a1;
input x1 .;
cards;
abcd
go shopping
DUT univarsity
he is driving
;
run;
data a2;
input x2 .;
cards;
golf shopping
she is driving
abcdf
DUT univars
;
run;
我想要最终的 table 具有匹配值:
abcd abcdf
go shopping golf shopping
DUT univarsity DUT univars
he is driving she is driving
此解决方案无法很好地扩展,但您明白了。使用 COMPGED 查找最近的匹配项并取最小值。这不适用于您没有很好匹配的情况。
您实际上是在进行模糊匹配,这是一个计算密集型过程。
proc sql;
create table want as
select t1.x1, t2.x2
from a1 as t1, a2 as t2
group by t1.x1
having compged(x1, x2) = min(compged(x1, x2));
quit;
在 2 tables a1, a2 中有 2 个相似的列(x1 vs x2)。我怎样才能匹配和排列它们? 我尝试了比较功能,但失败了。
data a1;
input x1 .;
cards;
abcd
go shopping
DUT univarsity
he is driving
;
run;
data a2;
input x2 .;
cards;
golf shopping
she is driving
abcdf
DUT univars
;
run;
我想要最终的 table 具有匹配值:
abcd abcdf
go shopping golf shopping
DUT univarsity DUT univars
he is driving she is driving
此解决方案无法很好地扩展,但您明白了。使用 COMPGED 查找最近的匹配项并取最小值。这不适用于您没有很好匹配的情况。
您实际上是在进行模糊匹配,这是一个计算密集型过程。
proc sql;
create table want as
select t1.x1, t2.x2
from a1 as t1, a2 as t2
group by t1.x1
having compged(x1, x2) = min(compged(x1, x2));
quit;