如何使用 PROC SQL 在 IN statemeng 中添加 LIKE 语句或 INDEX 函数

How to add a LIKE statement or INDEX function in the IN statemeng using PROC SQL

我使用下面的代码创建一个指标,如果代码中的值在另一个 table 的记录中找不到,则该指标为 0;如果所有相关值都与另一个 [=19] 的记录匹配,则该指标为 1 =].

proc sql;
create table test as
select id
      ,a.company_yr in (select company_yr from table2) 
                          and a.industry in (select industry from table2)
                          and a.sector in (select sector from table2) as match_ind
from work.table1 a;
quit;  

我的问题是 company_yr、行业和部门并不总是完全匹配,因为数据中有缩写或其他混淆(例如,'FORD MOTORS' 在 table 1 和 'FORD' 在 table2)。我需要一些方法来将 LIKE 语句或 INDEX 语句与 TRIM 语句结合使用,以允许我匹配字符串的各个部分以使指示器更准确。我还没有找到一种方法来有效地完成这个。

尝试这样的事情,将 "strip()" 函数替换为您想要完成所需规范化的任何内容,也许使用嵌套的 "compress()" 函数,以及一些 "upcase()" 以获得乐趣。您可以将子查询中的相等性转换为 LIKE,但不清楚您要匹配什么。

proc sql;
create table test as
select
    id,
    exists (select 1 from work.table2 b
            where strip(a.industry) = strip(b.industry)
            and strip(a.sector) = strip(b.sector)
    ) as match_ind
from work.table1 a;
quit;