<?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 Re: Limiting # of words in a Regex in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Limiting-of-words-in-a-Regex/m-p/749461#M235504</link>
    <description>&lt;P&gt;You could probaely use lookaorund. Here i just said a number followd by a periode.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data birad_q1;
	input report_text $1-130;
	cards;
BI-RADS: Post Procedure Mammograms for Marker Placement  COMMENTS:  None.  Addendum: DATE ADDENDUM DICTATED:  12/16/2025
Overall Final Assessment: BI-RADS Category 3.  Probably Benign.
Clinical assessment: BI-RADS score 4.  Suspicious.
;
run;

data birad_q2;
	set birad_q1;

	/* Create pattern using PERL to grab the keyword and subsequent score */
	text_out=prxparse("/bi.?rad(?=\s|s).+(\d{1,3})(?=\.)/i");

	if prxmatch(text_out, report_text) then
		do;
			score=input(prxposn(text_out, 1, report_text),8.);
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 22 Jun 2021 09:58:30 GMT</pubDate>
    <dc:creator>rudfaden</dc:creator>
    <dc:date>2021-06-22T09:58:30Z</dc:date>
    <item>
      <title>Limiting # of words in a Regex</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Limiting-of-words-in-a-Regex/m-p/749384#M235473</link>
      <description>&lt;P&gt;Hello community,&lt;/P&gt;&lt;P&gt;I've been implementing some regex code to capture BIRAD scores (scores that assess risk of breast cancer that can range from 0-6) and some of them, unfortunately, are buried within free text notes. While I have regex code (bi.?rads?\D*(.|\D+)?\d*) working reasonably well I'm having difficulty limiting the return of the digit after the BIRAD keyword. Some examples:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) BI-RAD category: 1 -- Regex code will capture entire string&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) BI-RADs 3 -- Regex code will capture entire string&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3)&amp;nbsp;BI-RADS CATEGORY EXPLANATION density date assessed: 9/24/2018 -- Regex captures up until the "9", or the September&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I obviously do not want to capture the '9' in the 3rd example. My initial thought was to limit the # of words that occur after the BIRAD keyword using some kind of word boundary count but I've difficulty operationalizing that, and I'm probably not thinking of a simpler approach. Any advice? Code example is attached.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, Brian.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 21:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Limiting-of-words-in-a-Regex/m-p/749384#M235473</guid>
      <dc:creator>BrianB4233</dc:creator>
      <dc:date>2021-06-21T21:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: Limiting # of words in a Regex</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Limiting-of-words-in-a-Regex/m-p/749418#M235491</link>
      <description>&lt;P&gt;Why not check for (and capture) a space after the digit?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 06:22:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Limiting-of-words-in-a-Regex/m-p/749418#M235491</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-06-22T06:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Limiting # of words in a Regex</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Limiting-of-words-in-a-Regex/m-p/749461#M235504</link>
      <description>&lt;P&gt;You could probaely use lookaorund. Here i just said a number followd by a periode.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data birad_q1;
	input report_text $1-130;
	cards;
BI-RADS: Post Procedure Mammograms for Marker Placement  COMMENTS:  None.  Addendum: DATE ADDENDUM DICTATED:  12/16/2025
Overall Final Assessment: BI-RADS Category 3.  Probably Benign.
Clinical assessment: BI-RADS score 4.  Suspicious.
;
run;

data birad_q2;
	set birad_q1;

	/* Create pattern using PERL to grab the keyword and subsequent score */
	text_out=prxparse("/bi.?rad(?=\s|s).+(\d{1,3})(?=\.)/i");

	if prxmatch(text_out, report_text) then
		do;
			score=input(prxposn(text_out, 1, report_text),8.);
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Jun 2021 09:58:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Limiting-of-words-in-a-Regex/m-p/749461#M235504</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2021-06-22T09:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: Limiting # of words in a Regex</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Limiting-of-words-in-a-Regex/m-p/749473#M235513</link>
      <description>&lt;P&gt;Another way if you really want to limit the word count:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;(bi.?rads?(\s[^\s\d]){1,3}\d+)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;but you still spend on the final digit(s).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Simpler would be keeping group 1 in something like:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;(bi-?rads?.*?)(--|date).*&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 10:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Limiting-of-words-in-a-Regex/m-p/749473#M235513</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-06-22T10:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: Limiting # of words in a Regex</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Limiting-of-words-in-a-Regex/m-p/749904#M235760</link>
      <description>Thank you all for your input, it's greatly appreciated.</description>
      <pubDate>Wed, 23 Jun 2021 16:19:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Limiting-of-words-in-a-Regex/m-p/749904#M235760</guid>
      <dc:creator>BrianB4233</dc:creator>
      <dc:date>2021-06-23T16:19:49Z</dc:date>
    </item>
  </channel>
</rss>

