<?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: Find A Postal Code In My Data in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Find-A-Postal-Code-In-My-Data/m-p/109543#M30484</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks DF - the link was helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Way up here in Canadakistan, our postal codes are formatted&amp;nbsp; as A#A #A# .&amp;nbsp; It's a shame SAS won't handle our postal codes the same as it does for ZIP codes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would need to do the pattern matching on at least 2 (maybe 3) address fields in order to insure that I got the postal code - as I said the data is a mess and the postal could have been entered just about anywhere.&amp;nbsp;&amp;nbsp; Do you know how to code the PRXMATCH to find this pattern?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone?&amp;nbsp;&amp;nbsp; Bueller?&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 17 Jul 2012 16:02:52 GMT</pubDate>
    <dc:creator>OS2Rules</dc:creator>
    <dc:date>2012-07-17T16:02:52Z</dc:date>
    <item>
      <title>Find A Postal Code In My Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Find-A-Postal-Code-In-My-Data/m-p/109541#M30482</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to be able to generate a valid mailing address from our customer master file.&amp;nbsp; Naturally, the data is a mess with no 2 records being formatted the same (since they are manually entered).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I would like to do is parse the address fields and extract out the postal codes.&amp;nbsp; It looks like this one field seems to have been entered correctly, that is, it appears to have the correct format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way I can parse the data looking for a postal code?&amp;nbsp;&amp;nbsp;&amp;nbsp; I don't have a copy of the PCCF so I can;t SQL it unfortunately.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance and don't forget to tip your waitress.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2012 15:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Find-A-Postal-Code-In-My-Data/m-p/109541#M30482</guid>
      <dc:creator>OS2Rules</dc:creator>
      <dc:date>2012-07-17T15:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Find A Postal Code In My Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Find-A-Postal-Code-In-My-Data/m-p/109542#M30483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It might help to have a sample of what your data looks like (with real people's information obscured of course!).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Generally though, post codes in your country will likely follow a specific pattern.&amp;nbsp; As such locating them is probably done best using Regular Experssions.&amp;nbsp; The SAS online help example 3 for the function PRXMATCH (&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002296115.htm" title="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002296115.htm"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002296115.htm&lt;/A&gt;) attempts to do just that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I imagine the SAS example is for US zip codes, so if you're not in the US then you'll need to find the pattern suitable for your own country.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wikipedia provides some examples for UK post codes, although I'd imagine the regex strings would need modified slightly to work with SAS.&amp;nbsp; &lt;A href="http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom" title="http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom"&gt;Postcodes in the United Kingdom - Wikipedia, the free encyclopedia&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DF.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2012 15:52:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Find-A-Postal-Code-In-My-Data/m-p/109542#M30483</guid>
      <dc:creator>DF</dc:creator>
      <dc:date>2012-07-17T15:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: Find A Postal Code In My Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Find-A-Postal-Code-In-My-Data/m-p/109543#M30484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks DF - the link was helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Way up here in Canadakistan, our postal codes are formatted&amp;nbsp; as A#A #A# .&amp;nbsp; It's a shame SAS won't handle our postal codes the same as it does for ZIP codes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would need to do the pattern matching on at least 2 (maybe 3) address fields in order to insure that I got the postal code - as I said the data is a mess and the postal could have been entered just about anywhere.&amp;nbsp;&amp;nbsp; Do you know how to code the PRXMATCH to find this pattern?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone?&amp;nbsp;&amp;nbsp; Bueller?&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2012 16:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Find-A-Postal-Code-In-My-Data/m-p/109543#M30484</guid>
      <dc:creator>OS2Rules</dc:creator>
      <dc:date>2012-07-17T16:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Find A Postal Code In My Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Find-A-Postal-Code-In-My-Data/m-p/109544#M30485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No worries.&amp;nbsp; I'm no expert on this - I largely put it together from the SAS examples (and the regex from &lt;A href="http://geekswithblogs.net/MainaD/archive/2007/12/03/117321.aspx" title="http://geekswithblogs.net/MainaD/archive/2007/12/03/117321.aspx"&gt; US and Canada zip code validation RegEx&lt;/A&gt;), but:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data ZipCodes;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile datalines dsd dlm=',';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input name: $16. zip:$40.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;Johnathan,A2A 2B2 a39js 93jaaj39&lt;/P&gt;&lt;P&gt;Seth,AAA B2B 3C3apples&lt;/P&gt;&lt;P&gt;Kim,39204B2B3C3B2B3C3&lt;/P&gt;&lt;P&gt;Samuel,93849-3843&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data ZipCodes2;&lt;/P&gt;&lt;P&gt;set ZipCodes;&lt;/P&gt;&lt;P&gt;regex = prxparse('/[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}/');&lt;/P&gt;&lt;P&gt;if prxmatch(regex, zip) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; postcode = prxposn(regex,0,zip);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop regex;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the examples given, this will pick up the first text string that matches the regex string.&amp;nbsp; This is pretty much as you described, although it excludes some characters in the first block (i.e. DFIOQUZ) - if this isn't correct you could just add them back in, or change it to A-Z.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If your data really has junk in it, then you'll need to be mindful of any false positives too.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2012 16:43:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Find-A-Postal-Code-In-My-Data/m-p/109544#M30485</guid>
      <dc:creator>DF</dc:creator>
      <dc:date>2012-07-17T16:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: Find A Postal Code In My Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Find-A-Postal-Code-In-My-Data/m-p/109545#M30486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks again DF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wound up doing something like this after&amp;nbsp; I&amp;nbsp; "RTFM" .....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; a&amp;nbsp; = prxmatch('/\w\d\w\s\d\w\d/',name_address_line_4);&amp;nbsp; &lt;/P&gt;&lt;P&gt; b&amp;nbsp; = prxmatch('/\w\d\w\s\d\w\d/',name_address_line_5);&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (a+b)&amp;gt;0 then output;&amp;nbsp; else delete;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and there was about a 99% success rate (the others were not postal codes that matched the pattern).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2012 16:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Find-A-Postal-Code-In-My-Data/m-p/109545#M30486</guid>
      <dc:creator>OS2Rules</dc:creator>
      <dc:date>2012-07-17T16:49:38Z</dc:date>
    </item>
  </channel>
</rss>

