我有两个具有多列的表。现在我想使用运算符相同的合并它们。 我的代码就像以下

proc sql;

    select a.*,b.*
    from tera.SFTP as a,home.SFTP_1 as b
    where a.zip_c like ('%b.zip_extract%')

;
quit;
.

我得到了PAGE中断消息,没有返回结果。 a.zip_c的列类型是char和length为50,而b.zip_extract它的字符长6。

有帮助吗?

解决方案

like上合并不是一个好主意;它不使用指数,并不使用否则使用大量优化。但是,有时是必要的。

但是,在SA中,我会以不同的方式[以及大多数其他SQLS ...]

proc sql;

    select a.*,b.*
    from tera.SFTP as a,home.SFTP_1 as b
    where find(a.zip_c,b.zip_extract)
;

quit;
.

这与类似的事情相同,但更有可能允许SA使用指数和优化,并且更清楚地写入。

处理可能的列长度问题,请使用修剪:

data have_a;
 length zip_c $50;
 input @1 zip_c $50.;
 datalines;
12345 99999
67890 99999
88001 99999
37013 99999
60037 99999
;;;;
run;

data have_b;
 length zip_extract $7;
 input zip_extract $;
 datalines;
12345
37013
99998
;;;;
run;

proc sql;
  title "No Rows!";
    select a.*,b.*
    from have_a as a,have_b as b
    where find(a.zip_c,b.zip_extract)
;

quit;
proc sql;
  title "Rows!";
    select a.*,b.*
    from have_a as a,have_b as b
    where find(a.zip_c,trim(b.zip_extract))
;

quit;
.

其他提示

问题是您在字符串中匹配b.zip_extract,而不是列。

尝试:

select a.*,b.*
from tera.SFTP as a,home.SFTP_1 as b
where a.zip_c like '%' || b.zip_extract || '%'
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top