<?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: Extract specific pattern in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Extract-specific-pattern/m-p/552619#M9219</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
 set have;
 pid=prxparse('/(?&amp;lt;=x)[^,]+(?=,)/i');
 call prxsubstr(pid,x,p,l);
 want=substr(x,p,l);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 20 Apr 2019 11:11:12 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-04-20T11:11:12Z</dc:date>
    <item>
      <title>Extract specific pattern</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-specific-pattern/m-p/552529#M9205</link>
      <description>&lt;P&gt;&lt;BR /&gt;X20l,p5,op3&lt;BR /&gt;cX3z,p4,op2(1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need help on extracting values that are after letter X and before first coma.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for :X20l,p5,op3----20l&lt;BR /&gt;for:cX3z,p4,op2(1)--3z&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2019 19:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-specific-pattern/m-p/552529#M9205</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2019-04-19T19:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: Extract specific pattern</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-specific-pattern/m-p/552533#M9206</link>
      <description>Such problems are best solved by using a regular expression. I can't post working code right now, you need the functions prxmatch and prxposn. The regular expression should be "X(.+),“</description>
      <pubDate>Fri, 19 Apr 2019 19:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-specific-pattern/m-p/552533#M9206</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-04-19T19:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Extract specific pattern</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-specific-pattern/m-p/552545#M9207</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data temp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; length extracted_value $ 10;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input char_str $ 1-20;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; extracted_value = prxchange('s/^[^X]*X(.*?)\x2C.*$/$1/',1,char_str);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; datalines;&lt;BR /&gt;X20l,p5,op3&lt;BR /&gt;cX3z,p4,op2(1)&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2019 20:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-specific-pattern/m-p/552545#M9207</guid>
      <dc:creator>Shemp</dc:creator>
      <dc:date>2019-04-19T20:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Extract specific pattern</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-specific-pattern/m-p/552594#M9215</link>
      <description>&lt;P&gt;As suggested, a regular expression will do the job:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
if _n_ = 1 then prxId + prxParse("/X(\w+?),/i");
length extracted_value $ 10;
input char_str $ 1-20;
if prxMatch(prxId, char_str) then
    extracted_value = prxPosn(prxId, 1, char_str);
drop prxId;
datalines;
X20l,p5,op3
cX3z,p4,op2(1)
;

proc print data=temp noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Remove the "i" in the pattern if the letter X at the beginning cannot be lowercase.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Apr 2019 04:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-specific-pattern/m-p/552594#M9215</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-04-20T04:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: Extract specific pattern</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-specific-pattern/m-p/552618#M9218</link>
      <description>&lt;P&gt;If it appeared only once, that would be easy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x $40.;
cards;
X20l,p5,op3
cX3z,p4,op2(1)
;
run;
data want;
 set have;
 pid=prxparse('/(?&amp;lt;=x).+?(?=,)/i');
 call prxsubstr(pid,x,p,l);
 want=substr(x,p,l);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Apr 2019 11:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-specific-pattern/m-p/552618#M9218</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-04-20T11:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: Extract specific pattern</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-specific-pattern/m-p/552619#M9219</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
 set have;
 pid=prxparse('/(?&amp;lt;=x)[^,]+(?=,)/i');
 call prxsubstr(pid,x,p,l);
 want=substr(x,p,l);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Apr 2019 11:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-specific-pattern/m-p/552619#M9219</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-04-20T11:11:12Z</dc:date>
    </item>
  </channel>
</rss>

