<?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 specific multiple numbers from String with delimiters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/extract-specific-multiple-numbers-from-String-with-delimiters/m-p/553479#M153916</link>
    <description>&lt;P&gt;I need to extract specific numbers from a variable (cmaeno). Some records have one number, others have multiple numbers I need. The numbers that I need are in the "( )" :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="what_i_have_what_i_need_20190423.JPG" style="width: 573px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28958i071B7871A988B330/image-size/large?v=v2&amp;amp;px=999" role="button" title="what_i_have_what_i_need_20190423.JPG" alt="what_i_have_what_i_need_20190423.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not no where to start syntax wise.&amp;nbsp;&amp;nbsp;Any help would be greatly appreciated.&lt;/P&gt;</description>
    <pubDate>Wed, 24 Apr 2019 01:02:33 GMT</pubDate>
    <dc:creator>mandonium</dc:creator>
    <dc:date>2019-04-24T01:02:33Z</dc:date>
    <item>
      <title>extract specific multiple numbers from String with delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-specific-multiple-numbers-from-String-with-delimiters/m-p/553479#M153916</link>
      <description>&lt;P&gt;I need to extract specific numbers from a variable (cmaeno). Some records have one number, others have multiple numbers I need. The numbers that I need are in the "( )" :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="what_i_have_what_i_need_20190423.JPG" style="width: 573px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28958i071B7871A988B330/image-size/large?v=v2&amp;amp;px=999" role="button" title="what_i_have_what_i_need_20190423.JPG" alt="what_i_have_what_i_need_20190423.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not no where to start syntax wise.&amp;nbsp;&amp;nbsp;Any help would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 01:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-specific-multiple-numbers-from-String-with-delimiters/m-p/553479#M153916</guid>
      <dc:creator>mandonium</dc:creator>
      <dc:date>2019-04-24T01:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: extract specific multiple numbers from String with delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-specific-multiple-numbers-from-String-with-delimiters/m-p/553482#M153918</link>
      <description>&lt;P&gt;Regular expression matching is well suited for this kind of work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
if not prxId then prxId + prxParse("/\((\d+)\)/");
set have;
start = 1;
stop = length(cmaeno);
call prxNext(prxID, start, stop, cmaeno, pos, len);
do while (pos &amp;gt; 0);
    cmaenum = input(prxPosn(prxId, 1, cmaeno), best.);
    output;
    call prxNext(prxID, start, stop, cmaeno, pos, len);
    end;
drop prxId start stop pos len;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT Code corrected, thanks to example provided by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt; .&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 01:37:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-specific-multiple-numbers-from-String-with-delimiters/m-p/553482#M153918</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-04-24T01:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: extract specific multiple numbers from String with delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-specific-multiple-numbers-from-String-with-delimiters/m-p/553483#M153919</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/102040"&gt;@mandonium&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically the same than what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;already posted while I was still coding.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  varWithText='abc (5) 23xx(9)abc94(345)4 73xy';
  output;
  stop;
run;

data want(drop=_:);
  set have;
  if _n_=1 then
    do;
      _expID = prxparse('/(?&amp;lt;=\()\d+(?=\))/');
      retain _expID;
    end;
  _start = 1;
  _stop = length(varWithText);

  /* 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(_expID, _start, _stop, varWithText, _pos, _len);

  do while (_pos &amp;gt; 0);
    found = substr(varWithText, _pos, _len);
/*    put found= _pos= length=;*/
    output;
    call prxnext(_expID, _start, _stop, varWithText, _pos, _len);
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code based on sample found here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002295965.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002295965.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 01:27:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-specific-multiple-numbers-from-String-with-delimiters/m-p/553483#M153919</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-04-24T01:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: extract specific multiple numbers from String with delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-specific-multiple-numbers-from-String-with-delimiters/m-p/553486#M153920</link>
      <description>&lt;P&gt;I'm getting a blank "cmaenum" column and a blank "text" column:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cm02;
if not prxId then prxId + prxParse("/\((\d+)\)/");
set toc6.cm;
start = 1;
stop = length(cmaeno);
call prxNext(prxID, start, stop, cmaeno, pos, len);
do while (pos &amp;gt; 0);
    cmaenum = input(substr(text, pos, len), best.);
    output;
    call prxNext(prxID, start, stop, cmaeno, pos, len);
    end;
drop prxId start stop pos len;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here's what I get:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="result_1.JPG" style="width: 207px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28959i7024A2708F2A43F4/image-size/large?v=v2&amp;amp;px=999" role="button" title="result_1.JPG" alt="result_1.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 01:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-specific-multiple-numbers-from-String-with-delimiters/m-p/553486#M153920</guid>
      <dc:creator>mandonium</dc:creator>
      <dc:date>2019-04-24T01:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: extract specific multiple numbers from String with delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-specific-multiple-numbers-from-String-with-delimiters/m-p/553487#M153921</link>
      <description>&lt;P&gt;Please check corrected version above.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 01:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-specific-multiple-numbers-from-String-with-delimiters/m-p/553487#M153921</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-04-24T01:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: extract specific multiple numbers from String with delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-specific-multiple-numbers-from-String-with-delimiters/m-p/553489#M153922</link>
      <description>&lt;P&gt;Thank you!&amp;nbsp; The corrected code worked perfectly.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 01:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-specific-multiple-numbers-from-String-with-delimiters/m-p/553489#M153922</guid>
      <dc:creator>mandonium</dc:creator>
      <dc:date>2019-04-24T01:46:35Z</dc:date>
    </item>
  </channel>
</rss>

