<?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: Character to Numeric in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686233#M24401</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/339357"&gt;@CurtisMackWSIPP&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My mistake on the math.&amp;nbsp; But ZIP codes only need numeric length 3, and they also only need 5 characters. So you do only save 2 bytes, but for different reasons.&lt;/P&gt;
&lt;P&gt;But why would you need to worry about leading zeros except when outputing results.&amp;nbsp; They are just integers so they are just as unique without the leading zero.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Zip+4 are not "integers". the position of the required dash character means that you cannot just remove it and treat the remainder as "integer". if you have a zip of 00004 and another of 00004-1234 and attempt to treat them as integers then 4 and 41234 are not going to go to the same state for postal services.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Sep 2020 22:05:02 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-09-23T22:05:02Z</dc:date>
    <item>
      <title>Character to Numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686122#M24387</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using this piece of code to convert a character variable to numeric:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;Zip_Code=input(Zip_Code, 10.);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but the variable still comes out character.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="marleeakerson_0-1600878391770.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49711iFF463886D825E424/image-size/medium?v=v2&amp;amp;px=400" role="button" title="marleeakerson_0-1600878391770.png" alt="marleeakerson_0-1600878391770.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 16:26:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686122#M24387</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2020-09-23T16:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686124#M24388</link>
      <description>&lt;P&gt;You can't change a variable from character to numeric. Zip_Code is initially character, no matter what you do to it, it will be character. (I suspect there are errors or warnings in the LOG as well)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to create a NEW numeric variable (with a different name) as follows&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Zip_Code1=input(Zip_Code, 10.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 16:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686124#M24388</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-23T16:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686125#M24389</link>
      <description>&lt;P&gt;Once a variable is defined as character you cannot change that. You would have to create a new variable such as:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   Zip_num=input(Zip_Code, 10.);
run;

 &lt;/PRE&gt;
&lt;P&gt;Now, why do you need a numeric value? Arithmetic with Zip codes is pretty meaningless.&lt;/P&gt;
&lt;P&gt;Plus your use of a 10. informat makes me suspect that you may have some +4 Zips like 12345-6789 in your data. Those will not convert to numeric at all without some serious manipulation.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 16:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686125#M24389</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-23T16:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686126#M24390</link>
      <description>&lt;P&gt;SAS variables are of fixed type.&amp;nbsp; They cannot be changed.&amp;nbsp; You must create a new variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want(drop = Zip_Code_str);
set have(rename = (Zip_Code = Zip_Code_str);
Zip_Code=input(Zip_Code_str, 10.);
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Sep 2020 16:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686126#M24390</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-23T16:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686136#M24391</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; has a good point.&amp;nbsp; If you convert 99999-9999 to numeric, you'll get a missing value and in essence lose your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really, truly need numeric, you could do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data	have;
	LENGTH	Zip_Code	$10.;
	INFILE	Datalines;
	INPUT	Zip_Code	$	&amp;amp;;
Datalines;
91024-4444
97805
91024-
99999-9999
91111
92222 2222
;
run;

data want;
   set have;
   Zip_num=input(COMPRESS(Zip_Code,,'kd'), 10.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The COMPRESS will take care of dashes or blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_1-1600880785296.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49713iFDDF5D90AD814D8C/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_1-1600880785296.png" alt="jimbarbour_1-1600880785296.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 17:06:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686136#M24391</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-23T17:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686170#M24396</link>
      <description>&lt;P&gt;A ZIP code is a&amp;nbsp;&lt;EM&gt;code&lt;/EM&gt;, not a number used for calculations. Keep it as character.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 18:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686170#M24396</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-23T18:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686195#M24397</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;A ZIP code is a&amp;nbsp;&lt;EM&gt;code&lt;/EM&gt;, not a number used for calculations. Keep it as character.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Unless you want to save 37 bytes per row.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 19:51:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686195#M24397</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-23T19:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686200#M24398</link>
      <description>&lt;P&gt;We don't know the defined length of the variable, but if it was 10, the saving is only 2 per observation.&lt;/P&gt;
&lt;P&gt;Empty space in character variables can be better dealt with with the COMPRESS option.&lt;/P&gt;
&lt;P&gt;And how do you deal with codes that have leading zeroes in a consistent, failsafe way?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 20:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686200#M24398</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-23T20:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686213#M24399</link>
      <description>&lt;P&gt;My mistake on the math.&amp;nbsp; But ZIP codes only need numeric length 3, and they also only need 5 characters. So you do only save 2 bytes, but for different reasons.&lt;/P&gt;
&lt;P&gt;But why would you need to worry about leading zeros except when outputing results.&amp;nbsp; They are just integers so they are just as unique without the leading zero.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 20:53:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686213#M24399</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-23T20:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686233#M24401</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/339357"&gt;@CurtisMackWSIPP&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My mistake on the math.&amp;nbsp; But ZIP codes only need numeric length 3, and they also only need 5 characters. So you do only save 2 bytes, but for different reasons.&lt;/P&gt;
&lt;P&gt;But why would you need to worry about leading zeros except when outputing results.&amp;nbsp; They are just integers so they are just as unique without the leading zero.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Zip+4 are not "integers". the position of the required dash character means that you cannot just remove it and treat the remainder as "integer". if you have a zip of 00004 and another of 00004-1234 and attempt to treat them as integers then 4 and 41234 are not going to go to the same state for postal services.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 22:05:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686233#M24401</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-23T22:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686234#M24402</link>
      <description>&lt;P&gt;And what about those extended zip codes &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;mentioned?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No, several hundred years of SAS experience here on the communities will tell you that codes are best kept as character.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 22:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686234#M24402</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-23T22:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686238#M24404</link>
      <description>&lt;P&gt;The poster didn't mention ZIP+4 Codes, and in my experience they are typically stored in a separate column. My user account does not reflect my 30 years of SAS experience.&amp;nbsp; I&amp;nbsp;specializing in GIS have a lot of experience with ZIP Codes.&amp;nbsp; I unusually store them as characters strings, but know that they can work just fine as integers.&amp;nbsp; For some situations you need them as integers.&amp;nbsp; Particularly when you are working across software platforms.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And then there is the case where you don't control the data source or are matching an output requirement.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 22:19:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686238#M24404</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-23T22:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686273#M24410</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/339357"&gt;@CurtisMackWSIPP&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The poster didn't mention ZIP+4 Codes, and in my experience they are typically stored in a separate column. My user account does not reflect my 30 years of SAS experience.&amp;nbsp; I&amp;nbsp;specializing in GIS have a lot of experience with ZIP Codes.&amp;nbsp; I unusually store them as characters strings, but know that they can work just fine as integers.&amp;nbsp; For some situations you need them as integers.&amp;nbsp; Particularly when you are working across software platforms.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And then there is the case where you don't control the data source or are matching an output requirement.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The reason I consider Zip+4 is the specific use of an F10. informat. If the values are only basic 5 digits then why pick an F10 informat? Might be habit or looking at the values and seeing the 10 columns a Zip+4 takes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data providers a clean enough to have the +4 in a separate column. I have to deal with "data" that will be in Excel and have a column that should be Zip codes in currency or date formats. At which point I am not terribly confident that going back to a general format actual has the original value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did ask &lt;STRONG&gt;why&lt;/STRONG&gt;. If we get a response to match some other requirement then see what the actual match use has to be. I can join data of different types sometimes if all the details are present.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 04:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Character-to-Numeric/m-p/686273#M24410</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-24T04:00:56Z</dc:date>
    </item>
  </channel>
</rss>

