<?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 information using regular expression in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/extract-specific-information-using-regular-expression/m-p/861676#M340358</link>
    <description>&lt;P&gt;Something like below should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines4 truncover;
  input have $200.;
  row_num=_n_;
  datalines4;
SEQ:2;NAME:xxx;START:2018-12-03;END:uk-uk-uk
SEQ:12;NAME:xxxxx;START:2018-12-03;END:
SEQ:22;NAME:xxxxxxx;START:uk-uk-uk;END:2012-uk-uk
SEQ:2;NAME:xxx;START:2018-12-03;END:uk-uk-uk SEQ:4;NAME:xxxx;START:2021-12-03;END:uk-uk-uk
 
SEQ:2;NAME:xxx
START:2018-12-03;
;;;;

data want(drop=_:);
  set have;
  length seq name $20;
  _prxid=prxparse('/seq:(\d*)\s*;name:([^;]*)/oi');
  _start=1;
  _stop =length(trim(have));
  call prxnext(_prxid,_start,_stop,have,_pos,_len);
  do until(_pos&amp;lt;=0);
    seq=prxposn(_prxid,1, have);
    name=prxposn(_prxid,2, have);
    output;
    call prxnext(_prxid,_start,_stop,have,_pos,_len);
  end;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If you only want to keep rows where there is a match change the do loop to&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1677659220131.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80978i467B1141B509A606/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1677659220131.png" alt="Patrick_0-1677659220131.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result running above code:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1677659318128.png" style="width: 646px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80979i89DBA86919E8027A/image-dimensions/646x176?v=v2" width="646" height="176" role="button" title="Patrick_0-1677659318128.png" alt="Patrick_0-1677659318128.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Mar 2023 08:28:48 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-03-01T08:28:48Z</dc:date>
    <item>
      <title>extract specific information using regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-specific-information-using-regular-expression/m-p/861663#M340354</link>
      <description>&lt;P&gt;I would like to extract some information from a list of strings using regular expression but I'm not familiar with it. Can anyone help? Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;length have $200;&lt;/P&gt;&lt;P&gt;have='SEQ:2;NAME:xxx;START:2018-12-03;END:uk-uk-uk';output;&lt;/P&gt;&lt;P&gt;have='SEQ:12;NAME:xxxxx;START:2018-12-03;END:';output;&lt;/P&gt;&lt;P&gt;have='SEQ:22;NAME:xxxxxxx;START:uk-uk-uk;END:2012-uk-uk';output;&lt;/P&gt;&lt;P&gt;have='SEQ:2;NAME:xxx;START:2018-12-03;END:uk-uk-uk SEQ:4;NAME:xxxx;START:2021-12-03;END:uk-uk-uk';output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The strings contain SEQ, NAME, START and END. I want to get SEQ and NAME.&lt;/P&gt;&lt;P&gt;The results will be:&lt;/P&gt;&lt;P&gt;SEQ:2;NAME:xxx;&lt;/P&gt;&lt;P&gt;SEQ:12;NAME:xxxxx;&lt;/P&gt;&lt;P&gt;SEQ:22;NAME:xxxxxxx;&lt;/P&gt;&lt;P&gt;SEQ:2;NAME:xxx;SEQ:4;NAME:xxxx;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 07:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-specific-information-using-regular-expression/m-p/861663#M340354</guid>
      <dc:creator>piao</dc:creator>
      <dc:date>2023-03-01T07:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: extract specific information using regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-specific-information-using-regular-expression/m-p/861676#M340358</link>
      <description>&lt;P&gt;Something like below should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines4 truncover;
  input have $200.;
  row_num=_n_;
  datalines4;
SEQ:2;NAME:xxx;START:2018-12-03;END:uk-uk-uk
SEQ:12;NAME:xxxxx;START:2018-12-03;END:
SEQ:22;NAME:xxxxxxx;START:uk-uk-uk;END:2012-uk-uk
SEQ:2;NAME:xxx;START:2018-12-03;END:uk-uk-uk SEQ:4;NAME:xxxx;START:2021-12-03;END:uk-uk-uk
 
SEQ:2;NAME:xxx
START:2018-12-03;
;;;;

data want(drop=_:);
  set have;
  length seq name $20;
  _prxid=prxparse('/seq:(\d*)\s*;name:([^;]*)/oi');
  _start=1;
  _stop =length(trim(have));
  call prxnext(_prxid,_start,_stop,have,_pos,_len);
  do until(_pos&amp;lt;=0);
    seq=prxposn(_prxid,1, have);
    name=prxposn(_prxid,2, have);
    output;
    call prxnext(_prxid,_start,_stop,have,_pos,_len);
  end;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If you only want to keep rows where there is a match change the do loop to&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1677659220131.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80978i467B1141B509A606/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1677659220131.png" alt="Patrick_0-1677659220131.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result running above code:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1677659318128.png" style="width: 646px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80979i89DBA86919E8027A/image-dimensions/646x176?v=v2" width="646" height="176" role="button" title="Patrick_0-1677659318128.png" alt="Patrick_0-1677659318128.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 08:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-specific-information-using-regular-expression/m-p/861676#M340358</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-03-01T08:28:48Z</dc:date>
    </item>
  </channel>
</rss>

