<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Using Regex to look for a date after a keyword in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Regex-to-look-for-a-date-after-a-keyword/m-p/786399#M251081</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm attempting to locate &amp;amp; output a date using some Regex that follows a keyword. The keyword in my scenario is 'Addendum' and it can occur multiple times. I'm looking for these keyword(s) in some free text that is loaded with line feeds/carriage returns etc. However I've worked on some Regex code that is successful - to a point.&lt;/P&gt;&lt;P&gt;I'm using PRXNEXT to capture every instance of 'Addendum', and then up to the next 15 words/non-word, and followed by a date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;if _n_ = 1 then do;
retain dt_pattern;
dt_pattern = prxparse("/(addend\w+(\W+\w+){0,15})\W+(\d{1,2}\s?(\.|\/|-)\s?\d{1,2}\s?(\.|\/|-)\s?\d{2,4})/i");
end;

start = 1;
stop = length(imp_rep_concat);

call prxnext(dt_pattern,start,stop,imp_rep_concat,pos,len);
	array comm[8] $150 addend1-addend8;
	array comm1[8] $30 amend_out1-amend_out8;

	do i = 1 to 8 while (pos &amp;gt; 0);
		comm(i) = upcase(substr(imp_rep_concat,pos,len));
		comm1(i) = prxPosn(dt_pattern, 3, imp_rep_concat);
	call prxnext(dt_pattern,start,stop,imp_rep_concat,pos,len);
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, in the example attached, there are 3 instances of 'Addendum' and this code is only picking up two. I've tried adjusting the&amp;nbsp;&lt;CODE class=""&gt;(\W+\w+){0,15})&lt;/CODE&gt; in the code to expand it from 15 but then it subsumes the next date. Any ideas/advice? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample is saved here as well:&lt;/P&gt;&lt;P&gt;&lt;A href="https://regex101.com/r/0eWTV9/1" target="_blank" rel="noopener"&gt;https://regex101.com/r/0eWTV9/1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Dec 2021 22:58:33 GMT</pubDate>
    <dc:creator>BrianB4233</dc:creator>
    <dc:date>2021-12-16T22:58:33Z</dc:date>
    <item>
      <title>Using Regex to look for a date after a keyword</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Regex-to-look-for-a-date-after-a-keyword/m-p/786399#M251081</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm attempting to locate &amp;amp; output a date using some Regex that follows a keyword. The keyword in my scenario is 'Addendum' and it can occur multiple times. I'm looking for these keyword(s) in some free text that is loaded with line feeds/carriage returns etc. However I've worked on some Regex code that is successful - to a point.&lt;/P&gt;&lt;P&gt;I'm using PRXNEXT to capture every instance of 'Addendum', and then up to the next 15 words/non-word, and followed by a date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;if _n_ = 1 then do;
retain dt_pattern;
dt_pattern = prxparse("/(addend\w+(\W+\w+){0,15})\W+(\d{1,2}\s?(\.|\/|-)\s?\d{1,2}\s?(\.|\/|-)\s?\d{2,4})/i");
end;

start = 1;
stop = length(imp_rep_concat);

call prxnext(dt_pattern,start,stop,imp_rep_concat,pos,len);
	array comm[8] $150 addend1-addend8;
	array comm1[8] $30 amend_out1-amend_out8;

	do i = 1 to 8 while (pos &amp;gt; 0);
		comm(i) = upcase(substr(imp_rep_concat,pos,len));
		comm1(i) = prxPosn(dt_pattern, 3, imp_rep_concat);
	call prxnext(dt_pattern,start,stop,imp_rep_concat,pos,len);
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, in the example attached, there are 3 instances of 'Addendum' and this code is only picking up two. I've tried adjusting the&amp;nbsp;&lt;CODE class=""&gt;(\W+\w+){0,15})&lt;/CODE&gt; in the code to expand it from 15 but then it subsumes the next date. Any ideas/advice? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample is saved here as well:&lt;/P&gt;&lt;P&gt;&lt;A href="https://regex101.com/r/0eWTV9/1" target="_blank" rel="noopener"&gt;https://regex101.com/r/0eWTV9/1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Dec 2021 22:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Regex-to-look-for-a-date-after-a-keyword/m-p/786399#M251081</guid>
      <dc:creator>BrianB4233</dc:creator>
      <dc:date>2021-12-16T22:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using Regex to look for a date after a keyword</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Regex-to-look-for-a-date-after-a-keyword/m-p/786420#M251091</link>
      <description>&lt;P&gt;how about not using regexp?&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;

x = "
ASSESSMENT:ACR BI-RADS Category 0 - Incomplete: Need additional
imaging evaluation.  

RECOMMENDATION: 
1: Additional imaging Right 

2: Additional imaging     

COMMENTS: Spot magnification views are recommended on the right.

Jane Doe 
 11/14/2017 10:08 AM
 
Addendum: 

ASSESSMENT: ACR BI-RADS 2 - Benign.

RECOMMENDATION: 
1: Routine screening mammogram Bilateral in 1 Year

COMMENTS:    

Jane Doe 
 11/22/2017 1:46 PM
 REPORT_TEXT EXAM: BREAST TOMOSYNTHESIS BI
ACCESSION: xxxxxxxxxxx
EXAM DATE AND TIME: 11/13/2017 11:09 AM


COMPARISON: Prior mammograms dated 2/19/2014.

TISSUE DENSITY: The breast tissue is heterogeneously dense (51% -
75%)

FINDINGS: 

Routine tomographic views were obtained bilaterally with 2-D
reconstructions. CAD was used for analysis.

Left Breast: There are no findings suspicious for malignancy.
There is no significant change from prior exam.

Right Breast: There is been interval development of calcification
in the upper outer quadrant of the right breast approximately 5
cm deep to the nipple, 3 cm lateral to the nipple, and 2 cm above
the nipple.


 
Addendum: EXAM: BREAST TOMOSYNTHESIS BI
ACCESSION: xxxxxxx
EXAM DATE AND TIME: 11/13/2017 11:09 AM


ADDENDUM: Prior mammographic studies dated 11/15/2016 and
10/11/2016 have now become available for comparison. 

The calcifications in the upper outer quadrant of the right
breast are visualized on these prior studies including
magnification views and have shown no interval change. These
appear benign.
"
;

n = countw(x," :;,.-","SM");
put n=;
length w $ 50;
keep a i d;
format d yymmdd10.;

do i = 1 to n;
  w = scan(x,i," :;,.-","SM");
  if index(upcase(w),"ADDENDUM") then a=i; /* mark if ADDENDUM found */ 
  d = input(w, ?? mmddyy10.);
  /*put i a d w;*/
  if d and a then do;
    output;
    a=0;
    d=.;
  end;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Dec 2021 08:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Regex-to-look-for-a-date-after-a-keyword/m-p/786420#M251091</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-12-17T08:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using Regex to look for a date after a keyword</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Regex-to-look-for-a-date-after-a-keyword/m-p/786790#M251251</link>
      <description>Thank you yabwon, your solution makes much more sense and is less cumbersome.</description>
      <pubDate>Mon, 20 Dec 2021 17:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Regex-to-look-for-a-date-after-a-keyword/m-p/786790#M251251</guid>
      <dc:creator>BrianB4233</dc:creator>
      <dc:date>2021-12-20T17:38:55Z</dc:date>
    </item>
  </channel>
</rss>

