<?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: prxparse with hyphens, numbers, and parenthesis in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/prxparse-with-hyphens-numbers-and-parenthesis/m-p/674822#M203242</link>
    <description>&lt;P&gt;What output you expect of each or all of the input strings ?&lt;/P&gt;</description>
    <pubDate>Wed, 05 Aug 2020 18:55:46 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2020-08-05T18:55:46Z</dc:date>
    <item>
      <title>prxparse with hyphens, numbers, and parenthesis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxparse-with-hyphens-numbers-and-parenthesis/m-p/674807#M203241</link>
      <description>&lt;P&gt;Does anyone know how to setup one prxparse expression to capture the following 5 pieces of text? What comes before or after the 5 pieces of text shown below can be anything.&lt;/P&gt;&lt;P&gt;1) Level space 1,2,3 (e.g. Level 1)&lt;/P&gt;&lt;P&gt;2) Level hyphen space 1,2,3 (e.g. Level- 2)&lt;/P&gt;&lt;P&gt;3) Level space hyphen space 1,2,3 (e.g. Level - 3)&lt;/P&gt;&lt;P&gt;4) Level hyphen 1,2,3 (e.g. Level-1)&lt;/P&gt;&lt;P&gt;5) Level space parenthesis around 1,2,3 (e.g. Level (2))&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 19:59:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxparse-with-hyphens-numbers-and-parenthesis/m-p/674807#M203241</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2020-08-05T19:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: prxparse with hyphens, numbers, and parenthesis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxparse-with-hyphens-numbers-and-parenthesis/m-p/674822#M203242</link>
      <description>&lt;P&gt;What output you expect of each or all of the input strings ?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 18:55:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxparse-with-hyphens-numbers-and-parenthesis/m-p/674822#M203242</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-05T18:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: prxparse with hyphens, numbers, and parenthesis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxparse-with-hyphens-numbers-and-parenthesis/m-p/674842#M203246</link>
      <description>&lt;P&gt;I'm searching the variable text_string for these 5 patterns.&lt;/P&gt;&lt;P&gt;The regular expression I'm asking about will go inside prxparse.&lt;/P&gt;&lt;P&gt;_prxid will be used in prxnext.&lt;/P&gt;&lt;P&gt;I want to create the variable incident_level.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;_prxid = prxparse('regular expression');&lt;BR /&gt;_start = 1;&lt;BR /&gt;_stop = length(text_string);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;call prxnext(_prxid, _start, _stop, trim(text_string), _pos, _len);&lt;BR /&gt;do while (_pos &amp;gt; 0);&lt;BR /&gt;incident_level = catx(' ',incident_level,substr(text_string, _pos, _len));&lt;BR /&gt;call prxnext(_prxid, _start, _stop, trim(text_string), _pos, _len);&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 19:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxparse-with-hyphens-numbers-and-parenthesis/m-p/674842#M203246</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2020-08-05T19:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: prxparse with hyphens, numbers, and parenthesis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxparse-with-hyphens-numbers-and-parenthesis/m-p/674943#M203282</link>
      <description>&lt;P&gt;Here is a solution: use PRX to find the whole level string, use COMPRESS with modifiers 'kd' (keep digits) to extract the digits:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input;
  text_string=_infile_;
cards;
afd ed 44 1) Level space 1,2,3 (e.g. Level 1) 3eyrt4drf Level 2 Level (1)
fdafdsfdsfsfsd 2) Level hyphen space 1,2,3 (e.g. Level- 2) fdsafafa
3) Level space hyphen space 1,2,3 (e.g. Level - 3)
4) Level hyphen 1,2,3 (e.g. Level-1)
5) Level space parenthesis around 1,2,3 (e.g. Level (2))
;run; 


data want;
  _prxid=prxparse('/Level \d+|Level ?- ?\d+|Level \(\d+\)/');
  set have;
  _start = 1;
  _stop = length(text_string);
  length incident_level $200;
  call prxnext(_prxid, _start, _stop, trim(text_string), _pos, _len);
  do while (_pos &amp;gt; 0);
    call catx(' ',incident_level,compress(substr(text_string, _pos, _len),,'kd'));
    call prxnext(_prxid, _start, _stop, trim(text_string), _pos, _len);
    end;
keep text_string incident_level;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, you may want to use the "I" modifier for you regular expression, if you have stuff like "LEVEL 1" or "level -1".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I changed the CATX function to CALL CATX, as that is more efficient (concatenates in place instead of copying the old string to temporary storage, concatenating there, and then copying the result back).&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 10:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxparse-with-hyphens-numbers-and-parenthesis/m-p/674943#M203282</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-08-06T10:47:08Z</dc:date>
    </item>
  </channel>
</rss>

