我需要在id字段上匹配2个数据集:
数据1:
00123abc5数据2:
23A我需要在id列上合并(SQL样式内连接)这两个数据集,但不是data1.id = …
使用 EXISTS 如果您只想要一个表中的行:
EXISTS
select d1.id from data1 d1 where exists (select 1 from data2 d2 where d1.id like concat('%', d2.id, '%');
实际上,在SAS中,我会使用标准的连接运算符:
select d1.id from data1 d1 where exists (select 1 from data2 d2 where d1.id like '%' || d2.id || '%';
你可以使用索引功能
data have; input id $9.; datalines; 00123abc5 00543abc5 ; data have1; input id $ col1; datalines; 23a 22 43a 72 73a 82 ; proc sql; create table want as select a.id, col1 from have a inner join have1 b on index(a.id, trim(b.id)) gt 0;