在 SAS PROC SQL 中搜索带撇号的字符串
Search for strings with apostrophes in SAS PROC SQL
有没有办法避免以下代码的警告?我对关闭警告的系统选项不太感兴趣,相反,我很好奇是否有更好的方法来编写此查询。
data quotey;
input string .;
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
而不是 like
。当然,这在 所有 情况下都行不通,但在你的情况下行得通。
proc sql ;
select * from quotey
where string contains "dn't"
;
quit;
否则有很多乱七八糟的处理方法。最简单的是使用单引号(以防止宏解析),但是您需要将单引号加倍 quote/apostrophe.
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;
这里你必须将 %
字符加倍(因为它被用作 'escape' 之类的)。
也尝试使用正则表达式:
title 'Hmmm...';
proc sql ;
select * from quotey
where prxmatch("/dn't/",string)>1;
;quit;
有没有办法避免以下代码的警告?我对关闭警告的系统选项不太感兴趣,相反,我很好奇是否有更好的方法来编写此查询。
data quotey;
input string .;
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
而不是 like
。当然,这在 所有 情况下都行不通,但在你的情况下行得通。
proc sql ;
select * from quotey
where string contains "dn't"
;
quit;
否则有很多乱七八糟的处理方法。最简单的是使用单引号(以防止宏解析),但是您需要将单引号加倍 quote/apostrophe.
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;
这里你必须将 %
字符加倍(因为它被用作 'escape' 之类的)。
也尝试使用正则表达式:
title 'Hmmm...';
proc sql ;
select * from quotey
where prxmatch("/dn't/",string)>1;
;quit;