<?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: How do I extract a keyword and subsequent text from a string and... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-keyword-and-subsequent-text-from-a-string-and/m-p/687797#M208851</link>
    <description>EVEN Better! Thanks for this follow up as it got me exactly what I needed.</description>
    <pubDate>Wed, 30 Sep 2020 12:55:36 GMT</pubDate>
    <dc:creator>Ksmit</dc:creator>
    <dc:date>2020-09-30T12:55:36Z</dc:date>
    <item>
      <title>How do I extract a keyword and subsequent text from a string and...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-keyword-and-subsequent-text-from-a-string-and/m-p/687333#M208642</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a text string variable tha reads:&lt;/P&gt;&lt;P&gt;"PLEASE LOAD TABLE 1394, SAME RATE AS TABLE 276."&lt;/P&gt;&lt;P&gt;Like this variable, there are other instances of unstructured data in this field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My working thought is to create keywords for the column to extract from the text.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this example,&amp;nbsp;&lt;EM&gt;TABLE&lt;/EM&gt; is the keyword. I would like to extract "Table 1394" into one variable and "Table 276" into another.&lt;/P&gt;&lt;P&gt;I've worked with Index, Scan, and find with varied results, but I am finding myself getting further away from my desired result. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if find(lowcase(txtstring),'table') &amp;gt;0 then table='table';&lt;BR /&gt;do i=1 to countw(txtstring," ");&lt;BR /&gt;if scan(lowcase(txtstring),i," ")=table then do;&lt;BR /&gt;after=strip(scan(txtstring,i+1," "));&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;output; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this produces only the first iteration of&amp;nbsp;&lt;EM&gt;table&lt;/EM&gt;:&lt;/P&gt;&lt;P&gt;&lt;U&gt;table after&lt;/U&gt;&lt;BR /&gt;table 276&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any guidance is greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-keyword-and-subsequent-text-from-a-string-and/m-p/687333#M208642</guid>
      <dc:creator>Ksmit</dc:creator>
      <dc:date>2020-09-28T20:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract a keyword and subsequent text from a string and...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-keyword-and-subsequent-text-from-a-string-and/m-p/687384#M208666</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  TEXT="PLEASE LOAD TABLE 1394, SAME RATE AS TABLE 276.  "; output;
  TEXT="PLEASE LOAD TABLE 139, SAME table 2  AS TABLE 27."; output;
data WANT;
  set HAVE;
  if _N_=1 then REGEX+prxparse('/(TABLE \d*)/i');
  START = 1;
  STOP  = length(TEXT);
  call prxnext(REGEX, START, STOP, TEXT, POS, LEN);
  do while (POS);
    STR   = substr(TEXT,POS,LEN);
    output;
    call prxnext(REGEX, START, STOP, TEXT, POS, LEN);
  end;
  keep STR;
run;
proc print data=WANT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt; &lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;STR&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;TABLE 1394&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;TABLE 276&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="l data"&gt;TABLE 139&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="l data"&gt;table 2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="l data"&gt;TABLE 27&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 01:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-keyword-and-subsequent-text-from-a-string-and/m-p/687384#M208666</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-29T01:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract a keyword and subsequent text from a string and...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-keyword-and-subsequent-text-from-a-string-and/m-p/687496#M208715</link>
      <description>Much appreciated Chris. This worked like a charm.&lt;BR /&gt;&lt;BR /&gt;I am thinking about putting this in a do loop for as many keywords as I have (presently 6) this way if any of the words populate in each iteration it will create a counter column per keyword.&lt;BR /&gt;&lt;BR /&gt;Thanks for starting me off.</description>
      <pubDate>Tue, 29 Sep 2020 12:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-keyword-and-subsequent-text-from-a-string-and/m-p/687496#M208715</guid>
      <dc:creator>Ksmit</dc:creator>
      <dc:date>2020-09-29T12:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract a keyword and subsequent text from a string and...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-keyword-and-subsequent-text-from-a-string-and/m-p/687691#M208792</link>
      <description>&lt;P&gt;You needn't do a DO loop.&lt;/P&gt;
&lt;P&gt;If say you want to also capture CHAIR 99, you can use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;REGEX+prxparse('/(TABLE \d*|CHAIR \d*)/i');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-keyword-and-subsequent-text-from-a-string-and/m-p/687691#M208792</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-30T00:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract a keyword and subsequent text from a string and...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-keyword-and-subsequent-text-from-a-string-and/m-p/687797#M208851</link>
      <description>EVEN Better! Thanks for this follow up as it got me exactly what I needed.</description>
      <pubDate>Wed, 30 Sep 2020 12:55:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-keyword-and-subsequent-text-from-a-string-and/m-p/687797#M208851</guid>
      <dc:creator>Ksmit</dc:creator>
      <dc:date>2020-09-30T12:55:36Z</dc:date>
    </item>
  </channel>
</rss>

