<?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: Search and extract a string based on a keyword (Perl Expression) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Search-and-extract-a-string-based-on-a-keyword-Perl-Expression/m-p/259622#M50235</link>
    <description>&lt;P&gt;Just in case you don't need the redundant "EXTRACT_ME[]," but only what's in the square brackets behind this keyword, you can modify Ksharp's Perl regular expression for example as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;pid=prxparse('/(?&amp;lt;=EXTRACT_ME\[)[^\]]+/oi');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This expression matches a sequence of&amp;nbsp;one or more characters not equal to "]" after the text "EXTRACT_ME[" (case-insensitive).&lt;/P&gt;</description>
    <pubDate>Tue, 29 Mar 2016 10:13:21 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2016-03-29T10:13:21Z</dc:date>
    <item>
      <title>Search and extract a string based on a keyword (Perl Expression)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-extract-a-string-based-on-a-keyword-Perl-Expression/m-p/259369#M50180</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; I have a variable that has different strings seperated by a pipe sign, Say as : VAR1 = STRING1|STRING2|STRING3 and so - on.&lt;/P&gt;
&lt;P&gt;Where only one string will contain a KEYWORD --&amp;gt; "EXTRACT_ME".&lt;/P&gt;
&lt;P&gt;And I would like to extract only the string that has EXTRACT_ME keyword. (an example is shown below)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can defenitely achieve it&amp;nbsp;with the help of a&amp;nbsp;DO loop and serach for the&amp;nbsp;KEYWORD in each string one by one and extract it.&lt;/P&gt;
&lt;P&gt;But I'm looking for something more effieicnt that really need to put it in a do loop. Maybe Perl Expression?&lt;/P&gt;
&lt;P&gt;Experts: Any advise? Appreciate your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="821"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="538"&gt;INPUT_VAR&lt;/TD&gt;
&lt;TD width="283"&gt;OUTPUT_VAR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;FIRST STRING|EXTRACT_ME[ABC]|SECOND STRING&lt;/TD&gt;
&lt;TD&gt;EXTRACT_ME[ABC]&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;STRING ONE|EXTRACT_ME[ABCDEFG]|STRING THREE|STRING FOUR&lt;/TD&gt;
&lt;TD&gt;EXTRACT_ME[ABCDEFG]&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 28 Mar 2016 16:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-extract-a-string-based-on-a-keyword-Perl-Expression/m-p/259369#M50180</guid>
      <dc:creator>geoonline</dc:creator>
      <dc:date>2016-03-28T16:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Search and extract a string based on a keyword (Perl Expression)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-extract-a-string-based-on-a-keyword-Perl-Expression/m-p/259374#M50181</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do it with a combination of string functions, but PERL will probably work better.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
string="FIRST STRING|EXTRACT_ME[ABC]|SECOND STRING";output;
string="STRING ONE|EXTRACT_ME[ABCDEFG]|STRING THREE|STRING FOUR";output;
run;

data want;
	set have;
	loc= index(string, "EXTRACT_ME");
	if loc&amp;gt;0 then end= index(substr(string, loc), "|");
	want=substr(string, loc, end-1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Mar 2016 16:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-extract-a-string-based-on-a-keyword-Perl-Expression/m-p/259374#M50181</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-28T16:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: Search and extract a string based on a keyword (Perl Expression)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-extract-a-string-based-on-a-keyword-Perl-Expression/m-p/259385#M50188</link>
      <description>&lt;P&gt;You'll need a slight modification, since LOC &amp;gt; 0 should control execution of the remainder of the statements (not just one).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A similar possibility:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if loc &amp;gt; 0 then want = scan(substr(string, loc), 1, '|');&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2016 16:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-extract-a-string-based-on-a-keyword-Perl-Expression/m-p/259385#M50188</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-28T16:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: Search and extract a string based on a keyword (Perl Expression)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-extract-a-string-based-on-a-keyword-Perl-Expression/m-p/259572#M50228</link>
      <description>&lt;PRE&gt;
What reason  force you to use PRX ?


data have;
string="FIRST STRING|EXTRACT_ME[ABC]|SECOND STRING";output;
string="STRING ONE|EXTRACT_ME[ABCDEFG]|STRING THREE|STRING FOUR";output;
run;
data want;
 set have;
 length want $ 200;
 pid=prxparse('/EXTRACT_ME\[\w+\]/oi');
 call prxsubstr(pid,string,p,l);
 if p then want=substr(string,p,l); 
 drop pid p l;
run;


&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Mar 2016 03:05:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-extract-a-string-based-on-a-keyword-Perl-Expression/m-p/259572#M50228</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-29T03:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Search and extract a string based on a keyword (Perl Expression)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-extract-a-string-based-on-a-keyword-Perl-Expression/m-p/259622#M50235</link>
      <description>&lt;P&gt;Just in case you don't need the redundant "EXTRACT_ME[]," but only what's in the square brackets behind this keyword, you can modify Ksharp's Perl regular expression for example as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;pid=prxparse('/(?&amp;lt;=EXTRACT_ME\[)[^\]]+/oi');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This expression matches a sequence of&amp;nbsp;one or more characters not equal to "]" after the text "EXTRACT_ME[" (case-insensitive).&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 10:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-extract-a-string-based-on-a-keyword-Perl-Expression/m-p/259622#M50235</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-29T10:13:21Z</dc:date>
    </item>
  </channel>
</rss>

