<?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: prxmatch / all character, all numeric or any alphanumeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-all-character-all-numeric-or-any-alphanumeric/m-p/526992#M143607</link>
    <description>&lt;P&gt;thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37783"&gt;@kiranv_&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Do you know or&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;if I can vectorize this with IML?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If nested in a loop, it works, otherwise no.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC IML;
USE HAVE;
READ ALL VAR _ALL_ INTO X [COLNAME=VARNAMES];
CLOSE;

/*doesn't work*/
FLAG= prxMatch("m/^[a-z]+$/imx",trim(X[,"codes"]));
PRINT X FLAG;


/*works*/
FLAG=J(NROW(X),1,.);

DO I=1 TO NROW(X);
FLAG[I] = prxMatch("m/^[a-z]+$/si",trim(X[I,"codes"]));
END;

PRINT X FLAG;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Jan 2019 17:06:21 GMT</pubDate>
    <dc:creator>acordes</dc:creator>
    <dc:date>2019-01-14T17:06:21Z</dc:date>
    <item>
      <title>prxmatch / all character, all numeric or any alphanumeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-all-character-all-numeric-or-any-alphanumeric/m-p/468946#M119844</link>
      <description>&lt;P&gt;I'm trying to flag 'codes' to a broad categories of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- all characters&lt;/P&gt;
&lt;P&gt;- all numeric&lt;/P&gt;
&lt;P&gt;- any alphanumeric&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I find categorizing codes for more generic conditions harder than specific conditions met shown below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help please?&amp;nbsp; What am I doing wrong? Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input codes $; 
datalines;
0D7Q8ZZ
XHRPXL2
0090T99
0090THJ
123456788
23456
234
0090T
0987F
HYDHDJH
;&lt;BR /&gt;
/*Help is appreciated to work below codes work out*/&lt;BR /&gt;
data x; set have;
if prxMatch("/^D+\s*$/o",codes) then flag = "all character"; 
if prxMatch("/^[a-z]+\s*$/o",codes) then flag = "all character"; 
if prxMatch("/^[a-z]*\s*$/o",codes) then flag = "all character"; &lt;BR /&gt;if prxMatch("/^w*\s*$/o",codes) then flag = "any alphanumeric"; 
if prxMatch("/^d+\s*$/o",codes) then flag = "all_numeric"; 
run;

proc freq data=x;
tables flag;
run;&lt;BR /&gt;&lt;BR /&gt;/*codes worked fine*/&lt;BR /&gt;&lt;BR /&gt;if prxMatch("/^\d{5}.{2}\s*$/o",codes) then flag="CPT1";&lt;BR /&gt;else if prxMatch("/^\d{4}F.{2}\s*$/o",codes) then flag = "CPT2";&lt;BR /&gt;else if prxMatch("/^\d{4}T.{2}\s*$/o",codes) then flag = "CPT3";&lt;BR /&gt;&lt;BR /&gt;else if prxMatch("/^V\d+\s*$/o",codes) then flag="VCODE";&lt;BR /&gt;else if prxMatch("/^E\d+\s*$/o",codes) then flag="ECODE";&lt;BR /&gt;else if prxMatch("/^\d{1}\s*$/o",codes) or &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;prxMatch("/^\d{2}\s*$/o",codes) or &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;prxMatch("/^\d{3}\s*$/o",codes) or &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;prxMatch("/^\d{4}\s*$/o",codes) then flag = "ICD9";&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jun 2018 20:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-all-character-all-numeric-or-any-alphanumeric/m-p/468946#M119844</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-06-09T20:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: prxmatch / all character, all numeric or any alphanumeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-all-character-all-numeric-or-any-alphanumeric/m-p/468957#M119849</link>
      <description>&lt;P&gt;something like below should work&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input codes $; 
datalines;
0D7Q8ZZ
XHRPXL2
0090T99
0090THJ
123456788
23456
234
0090T
0987F
HYDHDJH
;

data x; set have;
length flag $30.;
if prxMatch("/^[a-z]+$/i",trim(codes)) then flag = "all character"; 
 else if prxMatch("/^[0-9]+$/o",trim(codes)) then flag = "all numeric"; 
 else if prxMatch("/^[a-z0-9]+$/i",trim(codes)) then flag = "any alphanumeric"; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Jun 2018 23:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-all-character-all-numeric-or-any-alphanumeric/m-p/468957#M119849</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-06-09T23:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: prxmatch / all character, all numeric or any alphanumeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-all-character-all-numeric-or-any-alphanumeric/m-p/470283#M120388</link>
      <description>Btw, why trim() function needed here? Just trying to get full grasp of what you're doing here. Thanks.</description>
      <pubDate>Thu, 14 Jun 2018 12:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-all-character-all-numeric-or-any-alphanumeric/m-p/470283#M120388</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-06-14T12:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: prxmatch / all character, all numeric or any alphanumeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-all-character-all-numeric-or-any-alphanumeric/m-p/470968#M120573</link>
      <description>&lt;P&gt;just to remove leading and trailing blanks&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 04:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-all-character-all-numeric-or-any-alphanumeric/m-p/470968#M120573</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-06-18T04:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: prxmatch / all character, all numeric or any alphanumeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-all-character-all-numeric-or-any-alphanumeric/m-p/526992#M143607</link>
      <description>&lt;P&gt;thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37783"&gt;@kiranv_&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Do you know or&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;if I can vectorize this with IML?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If nested in a loop, it works, otherwise no.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC IML;
USE HAVE;
READ ALL VAR _ALL_ INTO X [COLNAME=VARNAMES];
CLOSE;

/*doesn't work*/
FLAG= prxMatch("m/^[a-z]+$/imx",trim(X[,"codes"]));
PRINT X FLAG;


/*works*/
FLAG=J(NROW(X),1,.);

DO I=1 TO NROW(X);
FLAG[I] = prxMatch("m/^[a-z]+$/si",trim(X[I,"codes"]));
END;

PRINT X FLAG;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jan 2019 17:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-all-character-all-numeric-or-any-alphanumeric/m-p/526992#M143607</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2019-01-14T17:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: prxmatch / all character, all numeric or any alphanumeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-all-character-all-numeric-or-any-alphanumeric/m-p/527005#M143611</link>
      <description>&lt;P&gt;In IML, &lt;A href="https://blogs.sas.com/content/iml/2014/05/05/iml-character-vectors.html" target="_self"&gt;all character vectors are a fixed length, which is the length of the longest element&lt;/A&gt;. Thus when you execute&lt;/P&gt;
&lt;P&gt;T&amp;nbsp;= trim(X);&lt;/P&gt;
&lt;P&gt;the TRIM function removes blanks from each element of X but the assignment operator essentially packs shorter elements with blanks so that every element of T has the same number of characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In other words, for vectors, the TRIM function is not doing what you think it is, but it does for scalars.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, you can tell the regular expression to ignore white space (or ignore at the end), which is probably what I'd suggest:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FLAG= prxMatch("m/^[a-z]+\s*$/imx", X);
PRINT FLAG X;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Another option would be to replace the regular expression with the ANY* functions in SAS. The general idea is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;hasDigit = anydigit(X);
hasPunct = anypunct(X);
hasAlpha = anyalpha(X);

allChar = hasAlpha &amp;amp; ^hasDigit;
allNum = hasDigit &amp;amp; ^hasAlpha;
PRINT allChar allNum X;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Jan 2019 17:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-all-character-all-numeric-or-any-alphanumeric/m-p/527005#M143611</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-01-14T17:51:13Z</dc:date>
    </item>
  </channel>
</rss>

