<?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 PRXmatch to find if last digit was specific string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PRXmatch-to-find-if-last-digit-was-specific-string/m-p/468550#M119693</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a ‘procedure code’ column (3 million records). I need to clean the data by categorizing the ‘procedure codes’ column to three different groups as below and then delete the records otherwise.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Category I codes are the five-digit numeric codes included in the main body of CPT.&lt;/LI&gt;
&lt;LI&gt;Category II Codes are alphanumeric and consist of four digits followed by the alpha character 'F’.&lt;/LI&gt;
&lt;LI&gt;Category III Codes are alphanumeric and consist of four digits followed by the alpha character 'T’.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I hope my code shown below had resolved for the Category 1. But not for category II and III.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help please?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Cruise&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input codes $ valid_flag $; 
datalines;
0D7Q8ZZ No
XHRPXL2 No
0BDN4ZZ No
123456788 No
23456 CAT1
234 No
0090T CAT3
0987F CAT2
HYDHDJH No
;

if lengthn(strip(codes)) gt 5 then CPT5=0; else CPT5=1;
if 99201&amp;lt;=codes&amp;lt;=99499 then cpt_code= 'management';
if 00100&amp;lt;=codes&amp;lt;=01999 then cpt_code= 'anasthesia';
if 10021&amp;lt;=codes&amp;lt;=69990 then cpt_code= 'surgery';
if 70010&amp;lt;=codes&amp;lt;=79999 then cpt_code= 'radiology';
if 80047&amp;lt;=codes&amp;lt;=89398 then cpt_code= 'pathology_lab'; 
if 90281&amp;lt;=codes&amp;lt;=99607 then cpt_code= 'medicine'; 
if '0500F'&amp;lt;=codes&amp;lt;='0503F'  then cpt_code= 'cat2'; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jun 2018 12:07:24 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2018-06-08T12:07:24Z</dc:date>
    <item>
      <title>PRXmatch to find if last digit was specific string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRXmatch-to-find-if-last-digit-was-specific-string/m-p/468550#M119693</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a ‘procedure code’ column (3 million records). I need to clean the data by categorizing the ‘procedure codes’ column to three different groups as below and then delete the records otherwise.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Category I codes are the five-digit numeric codes included in the main body of CPT.&lt;/LI&gt;
&lt;LI&gt;Category II Codes are alphanumeric and consist of four digits followed by the alpha character 'F’.&lt;/LI&gt;
&lt;LI&gt;Category III Codes are alphanumeric and consist of four digits followed by the alpha character 'T’.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I hope my code shown below had resolved for the Category 1. But not for category II and III.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help please?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Cruise&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input codes $ valid_flag $; 
datalines;
0D7Q8ZZ No
XHRPXL2 No
0BDN4ZZ No
123456788 No
23456 CAT1
234 No
0090T CAT3
0987F CAT2
HYDHDJH No
;

if lengthn(strip(codes)) gt 5 then CPT5=0; else CPT5=1;
if 99201&amp;lt;=codes&amp;lt;=99499 then cpt_code= 'management';
if 00100&amp;lt;=codes&amp;lt;=01999 then cpt_code= 'anasthesia';
if 10021&amp;lt;=codes&amp;lt;=69990 then cpt_code= 'surgery';
if 70010&amp;lt;=codes&amp;lt;=79999 then cpt_code= 'radiology';
if 80047&amp;lt;=codes&amp;lt;=89398 then cpt_code= 'pathology_lab'; 
if 90281&amp;lt;=codes&amp;lt;=99607 then cpt_code= 'medicine'; 
if '0500F'&amp;lt;=codes&amp;lt;='0503F'  then cpt_code= 'cat2'; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 12:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRXmatch-to-find-if-last-digit-was-specific-string/m-p/468550#M119693</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-06-08T12:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: PRXmatch to find if last digit was specific string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRXmatch-to-find-if-last-digit-was-specific-string/m-p/468555#M119694</link>
      <description>&lt;P&gt;The regular expressions&amp;nbsp;would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input codes $ valid_flag $; 
if prxMatch("/^\d{5}\s*$/o",codes) then flag = "CAT1";
else if prxMatch("/^\d{4}F\s*$/o",codes) then flag = "CAT2";
else if prxMatch("/^\d{4}T\s*$/o",codes) then flag = "CAT3";
else flag = "No";
datalines;
0D7Q8ZZ No
XHRPXL2 No
0BDN4ZZ No
123456788 No
23456 CAT1
234 No
0090T CAT3
0987F CAT2
HYDHDJH No
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jun 2018 00:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRXmatch-to-find-if-last-digit-was-specific-string/m-p/468555#M119694</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-06-08T00:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: PRXmatch to find if last digit was specific string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRXmatch-to-find-if-last-digit-was-specific-string/m-p/468602#M119715</link>
      <description>&lt;P&gt;My solution uses the regex posted by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;. Using formats could be less efficient, but if you have more expressions to check, testing them is easier and they can be used in other programs without duplicating them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
   invalue $Cat1Test
      "/^\d{5}\s*$/" (regexp) = 'CAT1'
      other = [$Test2Cat.]
   ;
   invalue $Test2Cat
      "/^\d{4}F\s*$/" (regexp) = 'CAT2'
      other = [$Test3Cat.]
   ;
   invalue $Test3Cat
      "/^\d{4}T\s*$/" (regexp) = 'CAT3'
      other = "No"
   ;
run;


data have;
   length codes $ 20 valid_flag check_flag $ 4;
   input codes $ valid_flag $; 

   check_flag = input(codes, $Cat1Test.);

   datalines;
0D7Q8ZZ No
XHRPXL2 No
0BDN4ZZ No
123456788 No
23456 CAT1
234 No
0090T CAT3
0987F CAT2
HYDHDJH No
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jun 2018 06:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRXmatch-to-find-if-last-digit-was-specific-string/m-p/468602#M119715</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-06-08T06:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: PRXmatch to find if last digit was specific string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRXmatch-to-find-if-last-digit-was-specific-string/m-p/468676#M119752</link>
      <description>&lt;P&gt;I'm trying to add in other rules like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else if prxMatch("/^\d{1}V\s*$/o",codes) then flag = "VCODE"; /*if initialized with letter V followed with numbers then VCODE*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else if prxMatch("/^\s*$/o",codes) then flag = "ALLCHACR"; /*if codes have nothing but letters then ALLCHAR*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where am i making mistakes in modifying your code above?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 12:50:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRXmatch-to-find-if-last-digit-was-specific-string/m-p/468676#M119752</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-06-08T12:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: PRXmatch to find if last digit was specific string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRXmatch-to-find-if-last-digit-was-specific-string/m-p/468690#M119760</link>
      <description>&lt;P&gt;I recommend reading the regex-documentation: &lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/67398/HTML/default/viewer.htm#p0s9ilagexmjl8n1u7e1t1jfnzlk.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lefunctionsref/67398/HTML/default/viewer.htm#p0s9ilagexmjl8n1u7e1t1jfnzlk.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;The regex for VCODE could be /^V\d+\s*$/&lt;/P&gt;
&lt;P&gt;and ALLCHARS is /^[a-z]+\s*$/&lt;/P&gt;
&lt;P&gt;Since all alphanumeric vars are filled with blanks, you have to add \s*.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 13:30:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRXmatch-to-find-if-last-digit-was-specific-string/m-p/468690#M119760</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-06-08T13:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: PRXmatch to find if last digit was specific string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRXmatch-to-find-if-last-digit-was-specific-string/m-p/468755#M119784</link>
      <description>&lt;P&gt;Thanks. SAS documentation helped. And I got it for V and ECODES and all non-digits like "TYUIO".&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; have; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; codes $; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12345&lt;/P&gt;
&lt;P&gt;123456&lt;/P&gt;
&lt;P&gt;1234F&lt;/P&gt;
&lt;P&gt;1234T&lt;/P&gt;
&lt;P&gt;123&lt;/P&gt;
&lt;P&gt;V1234&lt;/P&gt;
&lt;P&gt;E1234&lt;/P&gt;
&lt;P&gt;TYUIO&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; have1; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; flag $8&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; prxMatch(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"/^\d{5}\s*$/o"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;,codes) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; flag = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"CAT1"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; prxMatch(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"/^\d{4}F\s*$/o"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;,codes) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; flag = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"CAT2"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; prxMatch(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"/^\d{4}T\s*$/o"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;,codes) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; flag = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"CAT3"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; prxMatch(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"/^V\d{4}\s*$/o"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;,codes) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; flag = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"VCODE"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; prxMatch(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"/^E\d{4}\s*$/o"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;,codes) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; flag = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"ECODE"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; prxMatch(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"/^\D{5}\s*$/o"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;,codes) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; flag = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"NON_DIG"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 15:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRXmatch-to-find-if-last-digit-was-specific-string/m-p/468755#M119784</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-06-08T15:55:14Z</dc:date>
    </item>
  </channel>
</rss>

