<?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: 5 digit zip code in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/228964#M5591</link>
    <description>&lt;P&gt;If you have 5 character alphabetic characters, can't you use the following?&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; (anyalpha(ZIP)=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; and length(ZIP) = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ZipNum=input(Zip,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;5.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Oct 2015 18:41:24 GMT</pubDate>
    <dc:creator>Darrell_sas</dc:creator>
    <dc:date>2015-10-07T18:41:24Z</dc:date>
    <item>
      <title>5 digit zip code</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/228911#M5588</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One variable in my data set is zip code. It should be a 5 digit number, but of course, for some records it's text, for example,&amp;nbsp;"000NA","BMT ","BROOK","DR000","ENUE","FLR","L2J1P","P1470","ST000","UNKNO". Also some records just have “9” or some other single digit number. So in the original program, I read it as character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to look through all the records and any time zip codes is not a 5 digit number, change the value to missing? Then I can treat it as a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gene&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2015 15:19:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/228911#M5588</guid>
      <dc:creator>geneshackman</dc:creator>
      <dc:date>2015-10-07T15:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: 5 digit zip code</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/228927#M5589</link>
      <description>&lt;P&gt;Since you have already read the data then create a new variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;if length(ZIP) = 5 then ZipNum=input(Zip,5.);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May do what you want.&lt;/P&gt;
&lt;P&gt;One issue I would consider would be if the data source treated zips&amp;nbsp;such as&amp;nbsp;00009 as numeric and exported them as fewer than 5 digits.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2015 16:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/228927#M5589</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-10-07T16:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: 5 digit zip code</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/228943#M5590</link>
      <description>&lt;P&gt;Well, two questions. I tried that and got&lt;/P&gt;
&lt;P&gt;"NOTE: Invalid numeric data, ZIP='L2J1P' , at line 361 column 4."&amp;nbsp; So it seems to be having problems in that Zip is not numeric to begin with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you also wrote "since you already read the data". I can go back to the original data, reading it in with the input code,&lt;/P&gt;
&lt;P&gt;input&lt;/P&gt;
&lt;P&gt;@133 zip $char5.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you suggesting a way to modify that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2015 17:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/228943#M5590</guid>
      <dc:creator>geneshackman</dc:creator>
      <dc:date>2015-10-07T17:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: 5 digit zip code</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/228964#M5591</link>
      <description>&lt;P&gt;If you have 5 character alphabetic characters, can't you use the following?&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; (anyalpha(ZIP)=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; and length(ZIP) = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ZipNum=input(Zip,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;5.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2015 18:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/228964#M5591</guid>
      <dc:creator>Darrell_sas</dc:creator>
      <dc:date>2015-10-07T18:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: 5 digit zip code</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/228972#M5592</link>
      <description>&lt;P&gt;Why you need to treat it like a number? It is a zip code, you are not doing any arithmetic operation on it, so keep it Char. It will make your life a lot easier when dealing zip codes start with 0s, such as those from NJ.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data test;
infile cards truncover;
input zip $10.;
new_zip=ifc(prxmatch('/^\d{5}$/',strip(zip))&amp;gt;0, zip, '');
cards;
asdhg
78659
0987689
89ui
26543
u
.
;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Oct 2015 19:17:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/228972#M5592</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-10-07T19:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: 5 digit zip code</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/229000#M5593</link>
      <description>&lt;P&gt;Yes, of course, it has characters.&lt;/P&gt;&lt;P&gt;But you wish to do this&amp;nbsp;operation anyway right?&lt;/P&gt;&lt;P&gt;So you can&amp;nbsp;suppress the NOTE by using the colon modifier in the input statement.&lt;/P&gt;&lt;P&gt;Are you absolutely sure that chars are invalid data? If yes, you should report the&amp;nbsp;erroneous records to the data source to have them fix them.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2015 20:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/229000#M5593</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-10-07T20:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: 5 digit zip code</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/229028#M5597</link>
      <description>&lt;P&gt;Just variations to what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo﻿&lt;/a&gt;&amp;nbsp;posted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  infile cards truncover;
  input zip $10.;
  length new_zip1 new_zip2 $5;
  new_zip=ifc(prxmatch('/^\d{5}$/',strip(zip))&amp;gt;0, zip, '');
  if lengthn(zip)=5 and notdigit(strip(zip))=0 then new_zip1=zip;
  if prxmatch('/^\d{5} *$/',zip)&amp;gt;0 then new_zip2=zip;
  cards;
asdhg
78659
0987689
89ui
26543
u
.
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Oct 2015 22:16:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/229028#M5597</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-07T22:16:47Z</dc:date>
    </item>
    <item>
      <title>5 digit zip code</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/229106#M5609</link>
      <description>&lt;P&gt;Well, first, I want to delete any zip code that isn't 5 characters long. All zip codes must be 5 characters long (which can include leading 0). If it's character, that's fine, for this part, and this part looks easy to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, I want to delete any values that are not all numbers. All zip codes must be numerical, and cannot&amp;nbsp;include any&amp;nbsp;non numerical characters. This is the part that seems the most difficult. I don't want to just supress notes or messages about errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gene&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 12:34:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/229106#M5609</guid>
      <dc:creator>geneshackman</dc:creator>
      <dc:date>2015-10-08T12:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: 5 digit zip code</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/229114#M5612</link>
      <description>&lt;P&gt;Then I believe what Haikuo or I posted returns what you've asked for - and it leaves Zip codes character as it should be.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 13:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/5-digit-zip-code/m-p/229114#M5612</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-08T13:31:40Z</dc:date>
    </item>
  </channel>
</rss>

