可以在 SAS 中组合正则表达式查询吗?



我已经成功地在 SAS 中的正则表达式代码中实现了负面回溯。但是,有多个"单词"可能会否定我正在寻找的字符串。具体来说,我正在寻找一个短语(来自医学笔记),上面写着"碳青霉酶产生"或"碳青霉酶确认",有时这些短语前面可以加上"不产生碳青霉烯酶"或"可能的碳青霉烯酶产生",而这些我不想要。了解到负面回溯要求限定词(如果> 1)具有相同的长度后,我需要创建 2 个单独的正则表达式来捕获"not"和"possible",如下所示:

*!!! Create template to identify key phrases in the comment/note;
retain carba1 carba2 carba3;
if _n_ = 1 then do;     /*probable*/
 carba1 = prxparse("/(?<!nots)ca[bepr]w*?s*?(conf|posi|prod|+)/i");
 carba2 = prxparse("/(?<!possible|probables)ca[bepr]w*?s*? 
 (conf|posi|prod|+)/i");
 carba3 = prxparse("/(?<!not as)ca[bepr]w*?s*?(conf|posi|prod|+)/i");
end;
if prxmatch(carba1,as_comments) > 0 or prxmatch(carba2,as_comments) > 0 or
prxmatch(carba3,as_comments) > 0;

有没有一个词可以缩短执行时间,或者我是否坚持这个?任何建议/意见不胜感激。

如果它只有 4 个场景并且它们很简单。 您可以通过使用包含和不包含来简单完成此操作。

data have;
length string $200.;
infile datalines;
input string & $ ;
datalines;
this is cool and carbapenmase producing or  wow so nice
this is wow confirmed carbapenamase confirmed hello
now this positive for modified hodge test and later 
cool is my name not carbapenemase producing" or "the modified hodge hello
wow and wow previous possible carbapenamase producing hello
 Mr cool is hello
;

 data want;
  set have;
    where (string contains "carbapenmase producing" or
     string contains "carbapenamase confirmed")
   and  not (string contains "not carbapenemase producing" or 
   string contains "possible carbapenamase producing");
  run;

最新更新