<?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: Pattern matching to two different patterns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-to-two-different-patterns/m-p/879046#M347302</link>
    <description>&lt;P&gt;Where is the example values? Where are the examples of what is supposed to found as a pattern.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"The issue is that the valid values I want not to be flagged can be either a 4-digit string or a 5-digit string." Has no details of what the pattern you are looking for actually is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37814"&gt;@Walternate&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am doing some validity tests using pattern matching.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue is that the valid values I want not to be flagged can be either a 4-digit string or a 5-digit string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I set up:&lt;/P&gt;
&lt;DIV&gt;&lt;SPAN&gt; if _n_ = 1&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;then do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pattern_id3n=prxparse("/\d{5}/i");&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pattern_id3nb=prxparse("/\d{4}/i");&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; retain pattern:;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (prxmatch(pattern_id3n, id3n)&amp;nbsp; ne 1) or (prxmatch(pattern_id3nb, id3n)&amp;nbsp; ne 1) then do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;bad_id3n=id3n;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;bad_id_flag = 1;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not getting any bad messages, but I'm seeing values of 4-digits flagged as not valid so obviously that part of the pattern matching is not working correctly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Jun 2023 15:37:17 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-06-02T15:37:17Z</dc:date>
    <item>
      <title>Pattern matching to two different patterns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-to-two-different-patterns/m-p/879028#M347294</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am doing some validity tests using pattern matching.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue is that the valid values I want not to be flagged can be either a 4-digit string or a 5-digit string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I set up:&lt;/P&gt;
&lt;DIV&gt;&lt;SPAN&gt; if _n_ = 1&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;then do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pattern_id3n=prxparse("/\d{5}/i");&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pattern_id3nb=prxparse("/\d{4}/i");&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; retain pattern:;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (prxmatch(pattern_id3n, id3n)&amp;nbsp; ne 1) or (prxmatch(pattern_id3nb, id3n)&amp;nbsp; ne 1) then do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;bad_id3n=id3n;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;bad_id_flag = 1;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not getting any bad messages, but I'm seeing values of 4-digits flagged as not valid so obviously that part of the pattern matching is not working correctly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2023 15:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-to-two-different-patterns/m-p/879028#M347294</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2023-06-02T15:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern matching to two different patterns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-to-two-different-patterns/m-p/879046#M347302</link>
      <description>&lt;P&gt;Where is the example values? Where are the examples of what is supposed to found as a pattern.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"The issue is that the valid values I want not to be flagged can be either a 4-digit string or a 5-digit string." Has no details of what the pattern you are looking for actually is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37814"&gt;@Walternate&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am doing some validity tests using pattern matching.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue is that the valid values I want not to be flagged can be either a 4-digit string or a 5-digit string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I set up:&lt;/P&gt;
&lt;DIV&gt;&lt;SPAN&gt; if _n_ = 1&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;then do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pattern_id3n=prxparse("/\d{5}/i");&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pattern_id3nb=prxparse("/\d{4}/i");&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; retain pattern:;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if (prxmatch(pattern_id3n, id3n)&amp;nbsp; ne 1) or (prxmatch(pattern_id3nb, id3n)&amp;nbsp; ne 1) then do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;bad_id3n=id3n;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;bad_id_flag = 1;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not getting any bad messages, but I'm seeing values of 4-digits flagged as not valid so obviously that part of the pattern matching is not working correctly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2023 15:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-to-two-different-patterns/m-p/879046#M347302</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-06-02T15:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern matching to two different patterns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-to-two-different-patterns/m-p/879052#M347306</link>
      <description>&lt;P&gt;Valid:&lt;/P&gt;
&lt;P&gt;1234&lt;/P&gt;
&lt;P&gt;12345&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Invalid:&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;12&lt;/P&gt;
&lt;P&gt;123&lt;/P&gt;
&lt;P&gt;123456&lt;/P&gt;
&lt;P&gt;1234567&amp;nbsp;&lt;/P&gt;
&lt;P&gt;etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So anything 4-digits or 5-digits is valid but nothing else is.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2023 15:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-to-two-different-patterns/m-p/879052#M347306</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2023-06-02T15:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern matching to two different patterns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-to-two-different-patterns/m-p/879078#M347311</link>
      <description>&lt;P&gt;If that is the complete list of possible values just use the LENGTH() function to find the 4 and 5 digit strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;valid = length(string) in (4:5);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you also have values like 'FRED' then perhaps include a VERIFY() function call also.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;valid = (not verify(trim(string),'0123456789')) and length(string) in (4:5) ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Jun 2023 16:34:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-to-two-different-patterns/m-p/879078#M347311</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-02T16:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern matching to two different patterns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-to-two-different-patterns/m-p/879081#M347313</link>
      <description>&lt;P&gt;Why not say that in the regular expression?&lt;/P&gt;
&lt;P&gt;Use ^ to indicate it has to start at the beginning.&amp;nbsp; Add space and *$ at the end to indicate it can only be followed by the spaces used to pad the string to the full variable length.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  if _n_ = 1 then do;
    pattern_id3n=prxparse("/^\d{5} *$/");
    pattern_id3nb=prxparse("/^\d{4} *$/");
  end;
  retain pattern: ;
  drop pattern: ;
  input string $char20. ;
  test5=prxmatch(pattern_id3n,string);
  test4=prxmatch(pattern_id3nb,string);
cards;
123
1234
12345
123456
12 456
xxx 12345 yy
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Obs    string          test5    test4

 1     123               0        0
 2     1234              0        1
 3     12345             1        0
 4     123456            0        0
 5     12 456            0        0
 6     xxx 12345 yy      0        0&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Jun 2023 16:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-to-two-different-patterns/m-p/879081#M347313</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-02T16:48:59Z</dc:date>
    </item>
  </channel>
</rss>

