<?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: regex / prxmatch - find whole string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/regex-prxmatch-find-whole-string/m-p/763472#M241801</link>
    <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you very much for your fast reply and the additional link. This really helped me a lot and I think this is the solution!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lars&lt;/P&gt;</description>
    <pubDate>Tue, 24 Aug 2021 10:33:15 GMT</pubDate>
    <dc:creator>tietokone42</dc:creator>
    <dc:date>2021-08-24T10:33:15Z</dc:date>
    <item>
      <title>regex / prxmatch - find whole string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/regex-prxmatch-find-whole-string/m-p/763440#M241785</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;Dear SAS Community,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;I have a string variable in my data, which contains a mixture of different alphanumeric/special characters (really everything is possible). My task is to identify only special cases (=valid cases). Here is a minimal working example:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;Example Data:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;var1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="4"&gt;&lt;STRONG&gt;Abc 123456&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="4"&gt;Abc 1234567&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="4"&gt;B aBc 123&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="4"&gt;A&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="4"&gt;AbC&amp;nbsp; &amp;nbsp; 123&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="4"&gt;&lt;STRONG&gt;aBC 1243&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="4"&gt;123 abc 123&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;aBc123&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="4"&gt;Abc 12345&amp;nbsp;Abc 12345&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="4"&gt;&lt;STRONG&gt;abc 345&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;I only would like to find the highlighted cases, starting with three letters (upper or lower case possible) and followed by numbers (one is required, a max. of six is possible). Between the letters and the numbers one space is allowed but not required. I have tried for example the following code:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="4"&gt;DATA WORK.DATA_02;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="4"&gt;&amp;nbsp; &amp;nbsp;SET WORK.DATA_01;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; FOUND = 0;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if PRXMATCH ("/^[Aa][Bb][Cc] ?[1-9][0-9]?[0-9]?[0-9]?[0-9]?[0-9]?$/",var1) &amp;gt; 0 then FOUND = 1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="4"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;Beside that I have also tried the code without the $ at the end, with different boundaries \b and hundreds of other combinations. Unfortunately nothing works... The strange thing is that it seems that the code&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="4"&gt;^([Aa][Bb][Cc]\ ?[0-9][0-9]?[0-9]?[0-9]?[0-9]?[0-9]?)$&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;works in many online regex-checkers, but not within SAS.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;Can anybody help? Any hints, ideas or solutions? I am really desperately looking for an answer since days...&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;Thank you very much in advance!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;Best regards&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;Lars&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 08:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/regex-prxmatch-find-whole-string/m-p/763440#M241785</guid>
      <dc:creator>tietokone42</dc:creator>
      <dc:date>2021-08-24T08:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: regex / prxmatch - find whole string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/regex-prxmatch-find-whole-string/m-p/763453#M241787</link>
      <description>&lt;P&gt;I believe below RegEx will meet your requirement.&lt;/P&gt;
&lt;P&gt;You might find &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0s9ilagexmjl8n1u7e1t1jfnzlk.htm" target="_self"&gt;this link&lt;/A&gt; helpful.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dlm='|' dsd;
  input select :$1. var1 :$40.;
  datalines;
1|Abc 123456
0|Abc 1234567
0|B aBc 123
0|A
0|AbC    123
1|aBC 1243
0|123 abc 123
1|aBc123
0|Abc 12345 Abc 12345
1|abc 345
;


/*I only would like to find the highlighted cases, starting with three letters (upper or lower case possible) */
/*and followed by numbers (one is required, a max. of six is possible). */
/*Between the letters and the numbers one space is allowed but not required.*/
data want;
  set have;
  selected= prxmatch('/^[[:alpha:]]{3} ?\d{1,6}$/oi',strip(var1))&amp;gt;0;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1629793870113.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62911i402494DB94698457/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1629793870113.png" alt="Patrick_0-1629793870113.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 08:31:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/regex-prxmatch-find-whole-string/m-p/763453#M241787</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-08-24T08:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: regex / prxmatch - find whole string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/regex-prxmatch-find-whole-string/m-p/763470#M241799</link>
      <description>&lt;P&gt;Note that [:alpha:] matches all letters in the collating sequence used, including for example&amp;nbsp;é.&lt;/P&gt;
&lt;P&gt;This might be better. Or not.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt; prxmatch('/^[a-z]{3} ?\d{1,6}$/oi',strip(VAR))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 10:22:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/regex-prxmatch-find-whole-string/m-p/763470#M241799</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-24T10:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: regex / prxmatch - find whole string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/regex-prxmatch-find-whole-string/m-p/763472#M241801</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you very much for your fast reply and the additional link. This really helped me a lot and I think this is the solution!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lars&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 10:33:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/regex-prxmatch-find-whole-string/m-p/763472#M241801</guid>
      <dc:creator>tietokone42</dc:creator>
      <dc:date>2021-08-24T10:33:15Z</dc:date>
    </item>
  </channel>
</rss>

