<?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: I can match with prxmatch, need help with prxchange replacment? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/I-can-match-with-prxmatch-need-help-with-prxchange-replacment/m-p/834612#M329943</link>
    <description>&lt;P&gt;Or simply:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;prxchange('s/\b(\d+)(st|nd|rd|th)\b/\1/i', 1, Address1)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;\b matches any word boundary&lt;BR /&gt;\d+ matches one or more digits&lt;BR /&gt;\1 brings the match from the first set of parentheses (i.e. the digits)&lt;BR /&gt;the i suffix makes the match case insensitive&lt;/P&gt;</description>
    <pubDate>Thu, 22 Sep 2022 03:19:03 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2022-09-22T03:19:03Z</dc:date>
    <item>
      <title>I can match with prxmatch, need help with prxchange replacment?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-can-match-with-prxmatch-need-help-with-prxchange-replacment/m-p/834318#M329875</link>
      <description>&lt;P&gt;Hello all,&lt;BR /&gt;I am trying to do some address matching and am attempting pre-clean up and want to remove&amp;nbsp;(ST|ND|RD|TH) from any address line to have better matching where some add it some do not...&amp;nbsp; of course I have to match in the case where the word starts with a number not a street name like Sand street.&lt;BR /&gt;&lt;BR /&gt;have:&lt;BR /&gt;1104 E 148TH ST&lt;BR /&gt;1150 W 10TH ST&lt;BR /&gt;6836 34TH ST&lt;BR /&gt;4260 54TH ST&lt;BR /&gt;315 W 14TH ST&lt;BR /&gt;215 9TH ST&lt;BR /&gt;5601 47TH AVE&lt;BR /&gt;115 1ST AVE&lt;BR /&gt;1100 47TH ST&lt;BR /&gt;392 16TH ST&lt;BR /&gt;379 12TH ST&lt;BR /&gt;5550 N 1ST ST&lt;BR /&gt;4411 N 1ST ST&lt;BR /&gt;1325 E 4TH ST&lt;BR /&gt;1301 W 182ND ST&lt;BR /&gt;1230 WEST 177TH STREET&lt;BR /&gt;1023 14TH ST&lt;BR /&gt;750 W 10TH ST&lt;BR /&gt;321 16TH ST&lt;BR /&gt;1400 E 8TH ST&lt;BR /&gt;103 9TH STREET&lt;BR /&gt;125 EAST 6TH&lt;BR /&gt;418 W 8TH ST&lt;BR /&gt;131 E 28TH AVE&lt;BR /&gt;2565 E 58TH ST&lt;BR /&gt;631 12TH STREET&lt;BR /&gt;312 W 7TH ST&lt;BR /&gt;205 S 1ST ST&lt;BR /&gt;1900 18TH AVENUE&lt;BR /&gt;42145 30TH ST W&lt;BR /&gt;44514 20TH ST W&lt;BR /&gt;44701 32ND ST W&lt;BR /&gt;1350 3RD STREET&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;want&lt;BR /&gt;1104 E 148 ST&lt;BR /&gt;1150 W 10 ST&lt;BR /&gt;6836 34 ST&lt;BR /&gt;4260 54 ST&lt;BR /&gt;315 W 14 ST&lt;BR /&gt;215 9 ST&lt;BR /&gt;5601 47 AVE&lt;BR /&gt;115 1 AVE&lt;BR /&gt;1100 47 ST&lt;BR /&gt;392 16 ST&lt;BR /&gt;379 12 ST&lt;BR /&gt;5550 N 1 ST&lt;BR /&gt;4411 N 1 ST&lt;BR /&gt;1325 E 4 ST&lt;BR /&gt;1301 W 182 ST&lt;BR /&gt;1230 WEST 177 STREET&lt;BR /&gt;1023 14 ST&lt;BR /&gt;750 W 10 ST&lt;BR /&gt;321 16 ST&lt;BR /&gt;1400 E 8 ST&lt;BR /&gt;103 9 STREET&lt;BR /&gt;125 EAST 6&lt;BR /&gt;418 W 8 ST&lt;BR /&gt;131 E 28 AVE&lt;BR /&gt;2565 E 58 ST&lt;BR /&gt;631 12 STREET&lt;BR /&gt;312 W 7 ST&lt;BR /&gt;205 S 1 ST&lt;BR /&gt;1900 18 AVENUE&lt;BR /&gt;42145 30 ST W&lt;BR /&gt;44514 20 ST W&lt;BR /&gt;44701 32 ST W&lt;BR /&gt;1350 3 STREET&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table my_clean as
SELECT Id
      ,Name
      ,Country
      ,Address1
/*	  This code does not work */
	  ,compbl(prxchange('s/\s\d{1,}(ST|ND|RD|TH)\s/\s\d{1,}()\s/', -1, upper(Address1))) as clean_Address1
/*	  This line works just fine to find the bad guys */
	  ,prxmatch('/\s\d{1,}(ST|ND|RD|TH)\s/', upper(Address1)) as find_numsuffix1
	  ,Address2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt; ,compbl(upper(Address2)) as clean_Address2&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*	  This line works just fine to find the bad guys too */	  
	  ,prxmatch('/\s\d{1,}(ST|ND|RD|TH)\s/', upper(Address2)) as find_numsuffix2
      ,City
      ,State
      ,Zip
FROM my_source
;QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;example junk I am getting back:&lt;BR /&gt;&lt;BR /&gt;5550 N\s\d{1,}()\sST&lt;BR /&gt;4411 N\s\d{1,}()\sST&lt;BR /&gt;1325 E\s\d{1,}()\sST&lt;BR /&gt;1301 W\s\d{1,}()\sST&lt;BR /&gt;1230 WEST\s\d{1,}()\sSTREET&lt;BR /&gt;1023\s\d{1,}()\sST&lt;BR /&gt;750 W\s\d{1,}()\sST&lt;BR /&gt;321\s\d{1,}()\sST&lt;BR /&gt;1400 E\s\d{1,}()\sST&lt;BR /&gt;103\s\d{1,}()\sSTREET&lt;BR /&gt;125 EAST\s\d{1,}()\s&lt;BR /&gt;418 W\s\d{1,}()\sST&lt;BR /&gt;131 E\s\d{1,}()\sAVE&lt;BR /&gt;2565 E\s\d{1,}()\sST&lt;BR /&gt;631\s\d{1,}()\sSTREET&lt;BR /&gt;312 W\s\d{1,}()\sST&lt;BR /&gt;205 S\s\d{1,}()\sST&lt;BR /&gt;1900\s\d{1,}()\sAVENUE&lt;BR /&gt;42145\s\d{1,}()\sST W&lt;BR /&gt;44514\s\d{1,}()\sST W&lt;BR /&gt;44701\s\d{1,}()\sST W&lt;BR /&gt;1350\s\d{1,}()\sSTREET&lt;BR /&gt;44662\s\d{1,}()\sST W&lt;BR /&gt;235 E\s\d{1,}()\sST&lt;BR /&gt;4400 E\s\d{1,}()\sST&lt;BR /&gt;325 E\s\d{1,}()\sST&lt;BR /&gt;1575 WEST\s\d{1,}()\sSTREET&lt;BR /&gt;&lt;BR /&gt;in this case it is taking my replacement string as literal and It needs to bring back the part of the number and space it matched on leaving the&amp;nbsp;&lt;BR /&gt;ST | ND | RD | TH behind. I am not sure I have seen an example like this before. if so I have forgotten. I hope there is an easer way, that does not require a SAS server module because we do not have the software or budget.&lt;BR /&gt;PS data step or other options are okay too. I just mainly write proc sql&amp;nbsp; code...&amp;nbsp; TIA -KJ&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 16:24:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-can-match-with-prxmatch-need-help-with-prxchange-replacment/m-p/834318#M329875</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2022-09-20T16:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: I can match with prxmatch, need help with prxchange replacment?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-can-match-with-prxmatch-need-help-with-prxchange-replacment/m-p/834328#M329876</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43996"&gt;@kjohnsonm&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43996"&gt;@kjohnsonm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It needs to bring back the part of the number and space it matched on leaving the&amp;nbsp;ST | ND | RD | TH behind.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One way to achieve this is to put those two parts in parentheses in the search pattern and then refer to these "capturing groups" by their numbers (i.e. 1 and 3) in the form &lt;FONT face="courier new,courier"&gt;$1$3&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;\1\3&lt;/FONT&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;'s/&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;(&lt;/STRONG&gt;&lt;/FONT&gt;\s\d{1,}&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/FONT&gt;(ST|ND|RD|TH)&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;(&lt;/STRONG&gt;&lt;/FONT&gt;\s&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/FONT&gt;/&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;$1$3&lt;/STRONG&gt;&lt;/FONT&gt;/'&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Another option is to use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0s9ilagexmjl8n1u7e1t1jfnzlk.htm#n0u5ryrkyn3hvun17zcwp6fykynl" target="_blank" rel="noopener"&gt;look-ahead and look-behind behavior&lt;/A&gt;:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;'s/&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;(?&amp;lt;=\d)&lt;/STRONG&gt;&lt;/FONT&gt;(ST|ND|RD|TH)&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;(?=\s)&lt;/FONT&gt;&lt;/STRONG&gt;//'&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;That is, the first and third part of the pattern are not included in the final match so that the replacement pattern (i.e., for &lt;FONT face="courier new,courier"&gt;(ST|ND|RD|TH)&lt;/FONT&gt;) is just empty. Those look-ahead and look-behind assertions work only with fixed-width patterns, which is why I had to reduce the variable-width pattern&amp;nbsp;&lt;FONT face="courier new,courier"&gt;\s\d{1,}&lt;/FONT&gt; to &lt;FONT face="courier new,courier"&gt;\d&lt;/FONT&gt;. For your sample data it works as well, but the first suggestion is closer to your original plan.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 17:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-can-match-with-prxmatch-need-help-with-prxchange-replacment/m-p/834328#M329876</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-09-20T17:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: I can match with prxmatch, need help with prxchange replacment?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-can-match-with-prxmatch-need-help-with-prxchange-replacment/m-p/834612#M329943</link>
      <description>&lt;P&gt;Or simply:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;prxchange('s/\b(\d+)(st|nd|rd|th)\b/\1/i', 1, Address1)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;\b matches any word boundary&lt;BR /&gt;\d+ matches one or more digits&lt;BR /&gt;\1 brings the match from the first set of parentheses (i.e. the digits)&lt;BR /&gt;the i suffix makes the match case insensitive&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2022 03:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-can-match-with-prxmatch-need-help-with-prxchange-replacment/m-p/834612#M329943</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-09-22T03:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: I can match with prxmatch, need help with prxchange replacment?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-can-match-with-prxmatch-need-help-with-prxchange-replacment/m-p/835633#M330355</link>
      <description>PGStats &amp;amp;  FreelanceReinhard,&lt;BR /&gt;These both work, sorry for the delay in replying, since the other one was the first return and works I accepted it as the 'solution' but they both do the job nicely.  thank you both for replying.   &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;'s/(?&amp;lt;=\d)(ST|ND|RD|TH)(?=\s)//'&lt;BR /&gt;&lt;BR /&gt;...and...&lt;BR /&gt;&lt;BR /&gt;prxchange('s/\b(\d+)(st|nd|rd|th)\b/\1/i', 1, Address1)&lt;BR /&gt;&lt;BR /&gt;-Keith</description>
      <pubDate>Wed, 28 Sep 2022 15:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-can-match-with-prxmatch-need-help-with-prxchange-replacment/m-p/835633#M330355</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2022-09-28T15:13:24Z</dc:date>
    </item>
  </channel>
</rss>

