如何在SAS中仅在字符串中保留特定的日期模式?

如何在SAS中仅在字符串中保留特定的日期模式?,sas,Sas,我有一个包含单词、数字和日期(mm/dd/yy格式)的文本字符串,只想保留日期值 到目前为止,使用compress功能,我能够保留所有数字和“/”字符: data _null_; string = 'text 2342 12/11/15 text 54 11/01/14 49 text 10/23/16 423'; parsed = compress(string, '0123456789/ ', 'k'); put parsed; run; 返回: 12/11/15

我有一个包含单词、数字和日期(mm/dd/yy格式)的文本字符串,只想保留日期值

到目前为止,使用
compress
功能,我能够保留所有数字和“/”字符:

data _null_;
    string = 'text 2342 12/11/15 text 54 11/01/14 49 text 10/23/16 423';
    parsed = compress(string, '0123456789/ ', 'k');
    put parsed;
run;
返回:
12/11/15 54 11/01/14 49 10/23/16 423

我想要的是:
12/11/15 11/01/14 10/23/16

我如何才能做到这一点?

(改编自SAS的通话记录PRXNEXT例程)

结果数据集:


我最近一直在尝试学习PERL正则表达式,这是我所能得到的<代码>模式=prxparse('s |(\d\d\/\d\d\/\d\d\d)|测试|');测试=prxchange(模式,-1,日期)。这将用单词
TEST
替换所有日期,但我们想要做的恰恰相反。我还没有想出如何否定这种模式。我试图创建一个表达式,表示“如果不是这个确切的日期模式,请用空格替换它。”
data dates(keep = Text Dates);
   ExpressionID = prxparse('/\d{2}\/\d{2}\/\d{2}/');
   text = 'text 2342 12/11/15 text 54 11/01/14 49 text 10/23/16 423';
   length Dates $ 120;
   start = 1;
   stop = length(text);
      /* Use PRXNEXT to find the first instance of the pattern, */
      /* then use DO WHILE to find all further instances.       */
      /* PRXNEXT changes the start parameter so that searching  */
      /* begins again after the last match.                     */
   call prxnext(ExpressionID, start, stop, text, position, length);
      do while (position > 0);
         found = substr(text, position, length);
         put found= position= length=;
         Dates = catx(" ", dates, found);
         call prxnext(ExpressionID, start, stop, text, position, length);
      end;
run;