在SAS PROC SQL中搜索带撇号的字符串
有没有办法避免以下代码的警告?我对关闭警告的系统选项不太感兴趣,而是想知道是否有更好的方法来编写此查询在SAS PROC SQL中搜索带撇号的字符串,sas,proc-sql,Sas,Proc Sql,有没有办法避免以下代码的警告?我对关闭警告的系统选项不太感兴趣,而是想知道是否有更好的方法来编写此查询 data quotey; input string $9.; cards; shouldn't wouldn't couldn't dont won't ; run; proc print ; run; ods html close; ods html ; title 'Hmmm...'; proc sql ; select * from quotey where string l
data quotey;
input string $9.;
cards;
shouldn't
wouldn't
couldn't
dont
won't
;
run;
proc print ; run;
ods html close; ods html ;
title 'Hmmm...';
proc sql ;
select * from quotey
where string like "%dn't%"
;quit;
有几种不同的处理方法,但最简单的方法是使用
contains
,而不是像那样使用。当然,这在所有情况下都不起作用,但在你的情况下会起作用
proc sql ;
select * from quotey
where string contains "dn't"
;
quit;
有很多混乱的方法来处理它。最简单的方法是使用单引号(以防止宏解析),但随后需要将单引号/撇号加倍
proc sql ;
select * from quotey
where string like '%dn''t%'
;
quit;
您还可以通过几种方式使用%nrstr
(它防止使用字符解析宏)。这里有一个
proc sql ;
select * from quotey
where string like "%nrstr(%%)dn't%nrstr(%%)"
;quit;
这里您必须将%
字符加倍(因为它被用作“转义”类型)。还可以尝试使用正则表达式:
title 'Hmmm...';
proc sql ;
select * from quotey
where prxmatch("/dn't/",string)>1;
;quit;
我可以知道为什么要将单引号加倍吗?这就是如何在SAS中用相同引号类型的字符串中转义引号的方法。为什么>1'?它不应该是
>=1`吗?