<?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 Extract the next word after matching a long string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688140#M208996</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me with this? If I am getting the same data format as the example below. I'd like to pull the next word after matching the long string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;string = 'The shop will close on 8/21/20. They will have until 9/21/20 to reopen it again.'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;match1= 8/21/20&lt;/P&gt;&lt;P&gt;match2=9/21/20&lt;/P&gt;</description>
    <pubDate>Thu, 01 Oct 2020 09:20:23 GMT</pubDate>
    <dc:creator>Ja5ya</dc:creator>
    <dc:date>2020-10-01T09:20:23Z</dc:date>
    <item>
      <title>Extract the next word after matching a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688140#M208996</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me with this? If I am getting the same data format as the example below. I'd like to pull the next word after matching the long string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;string = 'The shop will close on 8/21/20. They will have until 9/21/20 to reopen it again.'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;match1= 8/21/20&lt;/P&gt;&lt;P&gt;match2=9/21/20&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 09:20:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688140#M208996</guid>
      <dc:creator>Ja5ya</dc:creator>
      <dc:date>2020-10-01T09:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the next word after matching a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688143#M208999</link>
      <description>&lt;P&gt;Are you matching on keywords like "on" and "until"?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 09:26:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688143#M208999</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-01T09:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the next word after matching a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688145#M209000</link>
      <description>&lt;P&gt;something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   ExpressionID = prxparse('/(\d+\/\d+\/\d+)/');
   text = 'The shop will close on 8/21/20. They will have until 9/21/20 to reopen it again.';
   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 &amp;gt; 0);
         match = substr(text, position, length);
         put match=;
         call prxnext(ExpressionID, start, stop, text, position, length);
      end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Oct 2020 09:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688145#M209000</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-10-01T09:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the next word after matching a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688155#M209003</link>
      <description>No, since "on" and "until" are very common words. So, need the whole phrase in front of it.</description>
      <pubDate>Thu, 01 Oct 2020 10:46:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688155#M209003</guid>
      <dc:creator>Ja5ya</dc:creator>
      <dc:date>2020-10-01T10:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the next word after matching a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688158#M209004</link>
      <description>Almost correct. Would need to assign different variables though. If the first match then one variable, if the send match then other variable.</description>
      <pubDate>Thu, 01 Oct 2020 11:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688158#M209004</guid>
      <dc:creator>Ja5ya</dc:creator>
      <dc:date>2020-10-01T11:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the next word after matching a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688159#M209005</link>
      <description>&lt;P&gt;Brute force:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string $80.;
datalines4;
The shop will close on 8/21/20. They will have until 9/21/20 to reopen it again.
;;;;

data want;
set have;
i = find(string,"The shop will close on");
if i then match1 = input(scan(substr(string,i),6," ."),mmddyy10.);
i = find(string,"They will have until");
if i then match2 = input(scan(substr(string,i),5," ."),mmddyy10.);
format match1 match2 mmddyy10.;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Oct 2020 11:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688159#M209005</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-01T11:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the next word after matching a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688179#M209008</link>
      <description>&lt;P&gt;&amp;nbsp;After a few struggle, this is what I came up.&amp;nbsp;&lt;BR /&gt;&amp;nbsp;There should be much better code but this is the best I can offer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   ExpressionID = prxparse('/(\d+\/\d+\/\d+)/');
   text = 'The shop will close on 8/21/20. They will have until 9/21/20 to reopen it again.';
   start = 1;
   stop = length(text);
   array match[2] $;
   call prxnext(ExpressionID, start, stop, text, position, length);
   	  i=0;
      do while (position &amp;gt; 0);
         i+1;
         match[i] = substr(text, position, length);
         put match[i]=;
         call prxnext(ExpressionID, start, stop, text, position, length);
      end;
      keep match1 match2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Oct 2020 12:54:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688179#M209008</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-10-01T12:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the next word after matching a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688180#M209009</link>
      <description>Thanks, this helps!</description>
      <pubDate>Thu, 01 Oct 2020 12:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688180#M209009</guid>
      <dc:creator>Ja5ya</dc:creator>
      <dc:date>2020-10-01T12:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the next word after matching a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688181#M209010</link>
      <description>Thanks!</description>
      <pubDate>Thu, 01 Oct 2020 12:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688181#M209010</guid>
      <dc:creator>Ja5ya</dc:creator>
      <dc:date>2020-10-01T12:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the next word after matching a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688258#M209040</link>
      <description>&lt;P&gt;You might be better of saving more of the 'pretext' (context previous to) of the date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;Find up to 5 'dates' in a slash date format and their pretexts.&lt;/P&gt;
&lt;PRE&gt;data have;
infile cards truncover;
input text $char100.;
datalines;
1/1/2020 opening
The shop will close on 8/21/20. They will have until 9/21/20 to reopen it again.
Somebody opened on 20AUG2020, a day before me!
Last call
closing 8/22/2020
;

data want(keep=text date: pretext:);
  set have;

  array pretext(3) $100 ;
  array datestr(3) $10;

  rxid = prxparse ('/(\d{1,2}\/\d{1,2}\/\d{2,4})/');

  start = 1;
  stop = -1;

  put /text=;

  do index = 1 to dim(datestr);
    prepos = start;
    call prxnext(rxid, start, stop, text, position, length);
    put prepos= start= stop= position= length=;

    if position &amp;gt; prepos then 
      pretext(index) = substr(text, prepos, position-prepos);

    if position &amp;gt; 0 then
      datestr(index) = substr(text, position, length);
    else
      pretext(index) = substr(text, start);

    if length = 0 then leave;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 15:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-next-word-after-matching-a-long-string/m-p/688258#M209040</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-10-01T15:34:20Z</dc:date>
    </item>
  </channel>
</rss>

