<?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: Perl Reg Expression in Array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Perl-Reg-Expression-in-Array/m-p/818246#M322985</link>
    <description>&lt;P&gt;Works fine for me.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input (dx1-dx3) ($) ;
cards;
J11 . .
. J11 .
. xJ11 .
;

data want;
  set have;
  arrary test dx1-dx3;
  flu1=0;
  flu2=0;
  do i=1 to dim(test) while (not flu1);
    flu1 = test[i]=:'J11';
  end;
  do i=1 to dim(test) while (not flu2);
    flu2 = 0 &amp;lt; PRXMATCH("/(J11)/",test[i]) ;
  end;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt; Obs    dx1    dx2     dx3    flu1    flu2    i
  1     J11                     1       1     2
  2            J11              1       1     3
  3            xJ11             0       1     3&lt;/PRE&gt;
&lt;P&gt;Notice also that you regex expression is NOT the same as your other test as it is looking for J11 any where in the string instead of only at the start.&lt;/P&gt;</description>
    <pubDate>Wed, 15 Jun 2022 02:30:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-06-15T02:30:05Z</dc:date>
    <item>
      <title>Perl Reg Expression in Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Perl-Reg-Expression-in-Array/m-p/818239#M322982</link>
      <description>&lt;P&gt;Hello - trying to compare the substr function to a perl reg expressions for searching for a string pattern across multiple variables. For whatever reason it seems like the array is only searching across one of the fields and then stopping but it works when using substr function. Is there additional syntax that needs to be added for this to work? The example below is simple, so it's fine to use SUBTR but there are cases where Perl Reg Expressions can really reduce the amount of logic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note:&lt;/STRONG&gt; &lt;EM&gt;&amp;amp;dx_field&lt;/EM&gt; refers to a list of 26 variables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;First Array - using SUBSTR searches across all variables (This works!):&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;ARRAY TEST {*} $ &amp;amp;DX_FIELD;&lt;BR /&gt;DO i=lbound(TEST) TO hbound(TEST);&lt;BR /&gt;IF (substr(TEST{i},1,3) = ("J11")) then flu=1 ;&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Second Array - uses Perl Reg Expression -&amp;nbsp; only produces a match when the first variable within &amp;amp;dx_field matches:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;ARRAY TEST2 {*} $ &amp;amp;dx_field;&lt;BR /&gt;DO i=lbound(TEST2) TO hbound(TEST2);&lt;BR /&gt;IF PRXMATCH("/(J11)/",TEST2[i]) THEN&lt;BR /&gt;FLU2 =1 ;&lt;BR /&gt;LEAVE;&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 00:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Perl-Reg-Expression-in-Array/m-p/818239#M322982</guid>
      <dc:creator>Krysia24</dc:creator>
      <dc:date>2022-06-15T00:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: Perl Reg Expression in Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Perl-Reg-Expression-in-Array/m-p/818246#M322985</link>
      <description>&lt;P&gt;Works fine for me.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input (dx1-dx3) ($) ;
cards;
J11 . .
. J11 .
. xJ11 .
;

data want;
  set have;
  arrary test dx1-dx3;
  flu1=0;
  flu2=0;
  do i=1 to dim(test) while (not flu1);
    flu1 = test[i]=:'J11';
  end;
  do i=1 to dim(test) while (not flu2);
    flu2 = 0 &amp;lt; PRXMATCH("/(J11)/",test[i]) ;
  end;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt; Obs    dx1    dx2     dx3    flu1    flu2    i
  1     J11                     1       1     2
  2            J11              1       1     3
  3            xJ11             0       1     3&lt;/PRE&gt;
&lt;P&gt;Notice also that you regex expression is NOT the same as your other test as it is looking for J11 any where in the string instead of only at the start.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 02:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Perl-Reg-Expression-in-Array/m-p/818246#M322985</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-15T02:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Perl Reg Expression in Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Perl-Reg-Expression-in-Array/m-p/818275#M322994</link>
      <description>&lt;P&gt;Your second example has an unconditional LEAVE statement inside the loop.&amp;nbsp; So regardless of the value of the first array element, the loop is only applied to the first element.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Drop the LEAVE.&amp;nbsp; Perhaps you want to use the UNTIL condition in your DO statements, as in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY TEST {*} $ &amp;amp;DX_FIELD;
DO i=lbound(TEST) TO hbound(TEST) until (flu=1);
IF (substr(TEST{i},1,3) = ("J11")) then flu=1 ;
END;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY TEST2 {*} $ &amp;amp;dx_field;
DO i=lbound(TEST2) TO hbound(TEST2) until (flu2=1);
IF PRXMATCH("/(J11)/",TEST2[i]) THEN
FLU2 =1 ;
END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 15:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Perl-Reg-Expression-in-Array/m-p/818275#M322994</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-06-15T15:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Perl Reg Expression in Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Perl-Reg-Expression-in-Array/m-p/818351#M323024</link>
      <description>&lt;PRE&gt;ARRAY TEST2 {*} $ &amp;amp;dx_field;
DO i=lbound(TEST2) TO hbound(TEST2);
   IF PRXMATCH("/(J11)/",TEST2[i]) THEN do;
      FLU2 =1 ;
      LEAVE;
   end; /* of the IF test result*/
END;
&lt;/PRE&gt;
&lt;P&gt;How to use the LEAVE to quit the loop when you find the first match. Not quit in the first iteration of the loop.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 15:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Perl-Reg-Expression-in-Array/m-p/818351#M323024</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-15T15:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: Perl Reg Expression in Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Perl-Reg-Expression-in-Array/m-p/819355#M323427</link>
      <description>&lt;P&gt;Well - I'm happy to see the solution was simple. Many thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2022 15:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Perl-Reg-Expression-in-Array/m-p/819355#M323427</guid>
      <dc:creator>Krysia24</dc:creator>
      <dc:date>2022-06-21T15:33:56Z</dc:date>
    </item>
  </channel>
</rss>

