<?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: CAT function not adding leading zeroes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/CAT-function-not-adding-leading-zeroes/m-p/548855#M152253</link>
    <description>&lt;P&gt;Instead of the CAT_ functions try this.&amp;nbsp; For either character ZIP or numeric ZIP.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
/* ZIP here is a number */ 
	zipNum=4321;
	zipNumCode=put(zipNum,z5.);
/* ZIP here is a character */
	zipChar='5432';
	zipCharCode=put(input(zipChar,5.),z5.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Apr 2019 17:46:22 GMT</pubDate>
    <dc:creator>JerryV</dc:creator>
    <dc:date>2019-04-05T17:46:22Z</dc:date>
    <item>
      <title>CAT function not adding leading zeroes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAT-function-not-adding-leading-zeroes/m-p/548822#M152240</link>
      <description>&lt;P&gt;I'm using zip codes, some of which start with a zero. I used the CATX, CATT, CATS, and CAT functions to try to concatenate a 0 then the remaining four digits to fix my current variable where the leading zero is missing. None of these worked. I'm left with a new variable with no leading zero for these. It's a character variable. (I need to fix this problem first because another issue I'll fix after this is dealing with xxxxx-xxxx zip codes. I don't think using LENGTH will fix my 4-digit issue since I'll need to chop off the correct side of my 9-digit ones later.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new; set old;&lt;BR /&gt;if length_zip=4 and state_code='CT' then zipcode=catt('0',zip);&lt;BR /&gt;if length_zip=4 and state_code='ME' then zipcode=catt('0',zip);&lt;BR /&gt;if length_zip=4 and state_code='MA' then zipcode=catt('0',zip);&lt;BR /&gt;if length_zip=4 and state_code='MA' then zipcode=catt('0',zip);&lt;BR /&gt;if length_zip=4 and state_code='NH' then zipcode=catt('0',zip);&lt;BR /&gt;if length_zip=4 and state_code='NJ' then zipcode=catt('0',zip);&lt;BR /&gt;if length_zip=4 and state_code='RI' then zipcode=catt('0',zip);&lt;BR /&gt;if length_zip=4 and state_code='VT' then zipcode=catt('0',zip);&lt;BR /&gt;else zipcode=zip; run;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 16:46:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAT-function-not-adding-leading-zeroes/m-p/548822#M152240</guid>
      <dc:creator>cadams47</dc:creator>
      <dc:date>2019-04-05T16:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: CAT function not adding leading zeroes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAT-function-not-adding-leading-zeroes/m-p/548855#M152253</link>
      <description>&lt;P&gt;Instead of the CAT_ functions try this.&amp;nbsp; For either character ZIP or numeric ZIP.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
/* ZIP here is a number */ 
	zipNum=4321;
	zipNumCode=put(zipNum,z5.);
/* ZIP here is a character */
	zipChar='5432';
	zipCharCode=put(input(zipChar,5.),z5.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 17:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAT-function-not-adding-leading-zeroes/m-p/548855#M152253</guid>
      <dc:creator>JerryV</dc:creator>
      <dc:date>2019-04-05T17:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: CAT function not adding leading zeroes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAT-function-not-adding-leading-zeroes/m-p/548929#M152261</link>
      <description>&lt;P&gt;Is your ZIPCODE variable numeric? How about ZIP? It might be educational to run proc contents on your data set OLD and show the results.&lt;/P&gt;
&lt;P&gt;If your variable ZIP is numeric your length_zip may not be "4" as you think.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   zip= 1234;
   length_zip= length(zip);
run;&lt;/PRE&gt;
&lt;P&gt;Yields length_zip of 12.&lt;/P&gt;
&lt;P&gt;If the data were read in correctly then the leading zero(s) would still be there. The reason they would disappear is if the were read as numeric values.&lt;/P&gt;
&lt;P&gt;In which case you may find that your data actually doesn't have any 5+4 as the - character would render them non-numeric when read.&lt;/P&gt;
&lt;P&gt;Please show the code on how you read your data into SAS.&lt;/P&gt;
&lt;P&gt;I'm going to guess that you used Proc Import in some form, which will guess the variable type and length. And depending on file type does so examining a very few records.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 19:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAT-function-not-adding-leading-zeroes/m-p/548929#M152261</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-05T19:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: CAT function not adding leading zeroes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAT-function-not-adding-leading-zeroes/m-p/549016#M152290</link>
      <description>&lt;P&gt;The variable ZIPCODE must already exist on your input dataset and be defined as numeric.&lt;/P&gt;
&lt;P&gt;So the CATT() is working fine but then SAS has to convert the string back into a number so the leading zero is gone again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to keep ZIPCODE as numeric then all you need to do is change the format so that it will display leading zeros.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format zipcode z5.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to make it character then you have to remove (or rename) the old variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new; 
  set old(drop=zipcode);
  zipcode=put(zip,z5.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Apr 2019 05:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAT-function-not-adding-leading-zeroes/m-p/549016#M152290</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-06T05:25:21Z</dc:date>
    </item>
  </channel>
</rss>

