<?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: Regular expression: Negative Lookahead in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Regular-expression-Negative-Lookahead/m-p/617121#M180779</link>
    <description>&lt;P&gt;Sorry, I should have included this in the original post. It should look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;'W EXAMPLE ROAD'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'N 108TH STREET'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'S MAIN'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'SOUTH OAK ROAD'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'EAST MAIN STREET APT'&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; I already have code to remove second unit designators such as 'APT', 'APARTMENT', 'UNIT', ect.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jan 2020 03:45:55 GMT</pubDate>
    <dc:creator>Stuart_P</dc:creator>
    <dc:date>2020-01-14T03:45:55Z</dc:date>
    <item>
      <title>Regular expression: Negative Lookahead</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-expression-Negative-Lookahead/m-p/617104#M180772</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I need to remove the apartment number&amp;nbsp;(secondary unit) in some dirty data.&amp;nbsp; The apartment number comes in many different flavors such as shown in the code below.&amp;nbsp; I am trying to use PRXCHANGE to remove all matches, along with a negative lookahead such as (?!TH) to not match any street names such as '108TH'.&amp;nbsp; The negative lookbehind can be expanded to (?!ST|ND|RD|TH) for firST, secoND, thiRD, and any i-th.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help concocting a regex for this. So far my regex is not working, I can get it to take all words with numbers out, but can't get the negative look ahead to work in conjunction.&amp;nbsp;&lt;BR /&gt;Currently, I have &lt;CODE class=" language-sas"&gt;"s/\b(([#A-Z]*)([0-9]+)([#A-Z]*))(?!ST|ND|RD|TH)\bs//"&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;s/&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;is required for PRXCHANGE. I have not gotten it to work otherwise.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;\b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;is for the word boundary&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;([#A-Z]*)&amp;nbsp; is to match any number of alpha characters plus #&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;([0-9]+)&amp;nbsp; &amp;nbsp;the word needs to have at least one numeric character&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;([#A-Z]*)&amp;nbsp; the alpha characters can also appear afterwards&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;(?!ST|ND|RD|TH) &amp;nbsp; &amp;nbsp;is the negative look ahead&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dirty;
var='W EXAMPLE ROAD #707'; output;
var='N 108TH STREET'; output;
var='S MAIN #D44'; output;
var='SOUTH OAK ROAD 1C'; output;
var='EAST MAIN STREET APT 4 B'; output;
run;&lt;BR /&gt;
data clean;
set dirty;
*Remove string matches with numeric optionally mixed with alpha (to remove apartment numbers such as: 3B, 3, B3, #3, 3#, #3B);
*^(?!TH) specifies not to match words ending with 'TH';
*s/ is required at both ends. I dont know why, something about replacement text.;
var2 = PRXCHANGE("s/\b(([#A-Z]*)([0-9]+)([#A-Z]*))(?!TH)\bs//",-1, var);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output should be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;'W EXAMPLE ROAD'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'N 108TH STREET'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'S MAIN'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'SOUTH OAK ROAD'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'EAST MAIN STREET APT'&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: to add expected output and change 'look behind' to 'look ahead'&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 03:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-expression-Negative-Lookahead/m-p/617104#M180772</guid>
      <dc:creator>Stuart_P</dc:creator>
      <dc:date>2020-01-14T03:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Regular expression: Negative Lookahead</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-expression-Negative-Lookahead/m-p/617117#M180778</link>
      <description>&lt;P&gt;what should be the output from the data you have given&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 03:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-expression-Negative-Lookahead/m-p/617117#M180778</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2020-01-14T03:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: Regular expression: Negative Lookahead</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-expression-Negative-Lookahead/m-p/617121#M180779</link>
      <description>&lt;P&gt;Sorry, I should have included this in the original post. It should look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;'W EXAMPLE ROAD'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'N 108TH STREET'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'S MAIN'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'SOUTH OAK ROAD'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'EAST MAIN STREET APT'&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; I already have code to remove second unit designators such as 'APT', 'APARTMENT', 'UNIT', ect.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 03:45:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-expression-Negative-Lookahead/m-p/617121#M180779</guid>
      <dc:creator>Stuart_P</dc:creator>
      <dc:date>2020-01-14T03:45:55Z</dc:date>
    </item>
  </channel>
</rss>

