<?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: reg ex extract in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/reg-ex-extract/m-p/774793#M246275</link>
    <description>&lt;P&gt;Doesn't sound like something that need regex.&amp;nbsp; Just use INDEX(), SUBSTRN() and SCAN().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  length string $50 case $10 ;
  input string $50.;
  loc = index(upcase(string),'CASE');
  if loc then case=scan(substrn(string,loc+4),1,'/');
cards;
Blah blah/Case123/Blah blah
Blah blah
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    string                         case    loc

 1     Blah blah/Case123/Blah blah    123      11
 2     Blah blah                                0

&lt;/PRE&gt;</description>
    <pubDate>Mon, 18 Oct 2021 04:50:01 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-10-18T04:50:01Z</dc:date>
    <item>
      <title>reg ex extract</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reg-ex-extract/m-p/774496#M246172</link>
      <description>&lt;P&gt;I have a long alpha numeric string with front slash delimiters throughout.&amp;nbsp; Within the string are specific 'case' id numbers.&amp;nbsp; I am trying to get everything in the string after the word 'Case', after that I can use the delimiter to drop everything after that.&amp;nbsp; I'm so out of practice with regex that I haven't been able to get there searching.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any help is appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 13:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reg-ex-extract/m-p/774496#M246172</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2021-10-15T13:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: reg ex extract</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reg-ex-extract/m-p/774499#M246173</link>
      <description>&lt;P&gt;I'm always open to suggestions but in case this can help anyone else I'm going to put my solution below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*identifies word case in string*/&lt;/P&gt;
&lt;P&gt;data p_case;&lt;BR /&gt;set check_case(obs=10 keep=Event_Log_Derived_Details);&lt;BR /&gt;if _N_ &amp;gt; 0 then do;&lt;BR /&gt;p_case = prxparse("/Case/");&lt;BR /&gt;end;&lt;BR /&gt;find_case = prxmatch(p_case,Event_Log_Derived_Details);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*uses place of 'Case' in string to get substring with '/' as the delimiter to extract the desired ID 'case' number*/&lt;/P&gt;
&lt;P&gt;data find_case;&lt;BR /&gt;set p_case;&lt;BR /&gt;case = scan(substr(Event_Log_Derived_Details,find_case),2,'/');&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 14:06:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reg-ex-extract/m-p/774499#M246173</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2021-10-15T14:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: reg ex extract</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reg-ex-extract/m-p/774510#M246179</link>
      <description>&lt;P&gt;A couple of concrete examples and the expected result is always a good idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May not even require regex.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 14:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reg-ex-extract/m-p/774510#M246179</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-15T14:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: reg ex extract</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reg-ex-extract/m-p/774789#M246274</link>
      <description>&lt;P&gt;basically what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;said. Can you provide an example of what you have and what you want?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm guessing what you have and what you want is somthing like this:&lt;/P&gt;
&lt;PRE&gt;data test;
    x = 'Case123:word/Case456:worrd/Case789:worrrd';
run;
data lines;
    set test;
    Length word $20;
    /* prxmatch returns the 1st found position */
    times = prxmatch('/Case/',x);/* returns 1 */
    times2= countw(x,'Case');
    do i = 1 to times2;
        word = scan(x,i,'Case'); 
        output;
    end;
run;
&lt;/PRE&gt;
&lt;P&gt;Afterwards you can handle the extracted "word" variable.&lt;/P&gt;
&lt;P&gt;For example, compress(word,,'/'); to remove the '/' at the end.&lt;/P&gt;
&lt;P&gt;Thus you don't need to regular expression. Instead, you can try countw function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, if you really want to regex, you can search for the "Call Prxnext" call routine :&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n1obc9u7z3225mn1npwnassehff0.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n1obc9u7z3225mn1npwnassehff0.htm&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;data test;
   ExpressionID = prxparse('/((Case[0-9]*:.*?\/)|(Case[0-9]*:.*?$))/');
   text = 'Case123:word/Case456:worrd/Case789:worrrd';
   start = 1;
   stop = length(text);
      /* 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.                     */
   output; /* for test purpose */
   call prxnext(ExpressionID, start, stop, text, position, length);
   output; /* for test purpose */
      do while (position &amp;gt; 0);
         found = substr(text, position, length);
         call prxnext(ExpressionID, start, stop, text, position, length);
         output;
      end;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Oct 2021 09:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reg-ex-extract/m-p/774789#M246274</guid>
      <dc:creator>happy_sas_kitty</dc:creator>
      <dc:date>2021-10-18T09:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: reg ex extract</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reg-ex-extract/m-p/774793#M246275</link>
      <description>&lt;P&gt;Doesn't sound like something that need regex.&amp;nbsp; Just use INDEX(), SUBSTRN() and SCAN().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  length string $50 case $10 ;
  input string $50.;
  loc = index(upcase(string),'CASE');
  if loc then case=scan(substrn(string,loc+4),1,'/');
cards;
Blah blah/Case123/Blah blah
Blah blah
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    string                         case    loc

 1     Blah blah/Case123/Blah blah    123      11
 2     Blah blah                                0

&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Oct 2021 04:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reg-ex-extract/m-p/774793#M246275</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-18T04:50:01Z</dc:date>
    </item>
  </channel>
</rss>

