<?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: Adding leading zeros to numeric,alphanumeric and character variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358360#M84179</link>
    <description>&lt;P&gt;Hi reeza&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;91&lt;/P&gt;&lt;P&gt;81&lt;/P&gt;&lt;P&gt;aaaaaa&lt;/P&gt;&lt;P&gt;bbbbbb&lt;/P&gt;&lt;P&gt;cfg014&lt;/P&gt;&lt;P&gt;456asd&lt;/P&gt;&lt;P&gt;4kj&lt;/P&gt;&lt;P&gt;gh4&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;000091&lt;/P&gt;&lt;P&gt;000081&lt;/P&gt;&lt;P&gt;aaaaaa&lt;/P&gt;&lt;P&gt;bbbbbb&lt;/P&gt;&lt;P&gt;cfg014&lt;/P&gt;&lt;P&gt;456asd&lt;/P&gt;&lt;P&gt;0004kj&lt;/P&gt;&lt;P&gt;000gh4&lt;/P&gt;&lt;P&gt;000000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried both :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;padded &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;charvar&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;best6&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;z6&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;and&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;xx = cats(repeat('0',6-length(x)-1), x);&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;cats somewhere is fine and somewhere is giving the error :&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"unknown func CATS and cannot be accessed" but with CATS i am getting the desired output&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;With the first thing only numeric values are getting populated with eading zeros rest are being changed to 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please give me a better format or an alternative for CATS/X/T/Q&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 May 2017 22:08:15 GMT</pubDate>
    <dc:creator>sayanapex06</dc:creator>
    <dc:date>2017-05-12T22:08:15Z</dc:date>
    <item>
      <title>Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358357#M84177</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is an urgent requirement that I need to fulfil, would highly appreciate it if you help on this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question :&lt;/P&gt;&lt;P&gt;I have data like :&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; test&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
    &lt;SPAN class="token function"&gt;length&lt;/SPAN&gt; A &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;4&lt;/SPAN&gt; ;
    &lt;SPAN class="token statement"&gt;infile&lt;/SPAN&gt; datalines&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
    &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; A&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
    A &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(A&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;best4&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;z4&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;81
1034
91
A46
6HJ
AAAAAA
F39000&lt;BR /&gt;DSUG08&lt;BR /&gt;CSDF85&lt;BR /&gt;000000&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want the output like :&lt;/P&gt;&lt;P&gt;000081&lt;/P&gt;&lt;P&gt;001034&lt;/P&gt;&lt;P&gt;000091&lt;/P&gt;&lt;P&gt;000A46&lt;/P&gt;&lt;P&gt;0006HJ&lt;/P&gt;&lt;P&gt;AAAAAA&lt;/P&gt;&lt;P&gt;F39000&lt;/P&gt;&lt;P&gt;DSUG08&lt;/P&gt;&lt;P&gt;CSDF85&lt;/P&gt;&lt;P&gt;000000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which is basically I need to add leaing 'zeros' if length is less than 6 but for all 6 length characters I need the same output unaltered. The desired output is given above&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need a particular format for doing this.&lt;/P&gt;&lt;P&gt;I dont need a temporary fix on this&lt;/P&gt;&lt;P&gt;I need a permanent solution as to whatever value comes for the field 'A' I get the output like stated above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Codes I tried :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;A &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(A&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;best4&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;z4&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;   ------- case 1&lt;BR /&gt;and&lt;BR /&gt;&lt;SPAN&gt;A = cats(repeat('0',6-length(A)-1), x); ------- case 2&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;case1 :&lt;BR /&gt;&lt;BR /&gt;Only the numeric records are getting populated with leading zeros and for rest it is coming as 0&lt;BR /&gt;&lt;BR /&gt;case2 :&lt;BR /&gt;&lt;BR /&gt;I am getting the desired output as stated above but for some cases I am getting error like :&lt;BR /&gt;&lt;BR /&gt;'Function CATS unknown or cannot be accessed.'&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Please provide me with a better format for doing this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 21:56:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358357#M84177</guid>
      <dc:creator>sayanapex06</dc:creator>
      <dc:date>2017-05-12T21:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358358#M84178</link>
      <description>&lt;P&gt;Is your data exactly as posted in the data step? You have 81 right after the datalines statement.&lt;/P&gt;
&lt;P&gt;The last record is longer than 6 characters so it has to get separated?&lt;/P&gt;
&lt;P&gt;How do you know the rules for separation, assume 6 characters per variable?&lt;/P&gt;
&lt;P&gt;What happens if the last variable is short when splitting it up, ie last set is only 3 chars?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have a mix of character/numeric so INPUT and Z6 format won't work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if you need a length of 6 why are you using 4 in the code?&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 22:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358358#M84178</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-12T22:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358360#M84179</link>
      <description>&lt;P&gt;Hi reeza&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;91&lt;/P&gt;&lt;P&gt;81&lt;/P&gt;&lt;P&gt;aaaaaa&lt;/P&gt;&lt;P&gt;bbbbbb&lt;/P&gt;&lt;P&gt;cfg014&lt;/P&gt;&lt;P&gt;456asd&lt;/P&gt;&lt;P&gt;4kj&lt;/P&gt;&lt;P&gt;gh4&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;000091&lt;/P&gt;&lt;P&gt;000081&lt;/P&gt;&lt;P&gt;aaaaaa&lt;/P&gt;&lt;P&gt;bbbbbb&lt;/P&gt;&lt;P&gt;cfg014&lt;/P&gt;&lt;P&gt;456asd&lt;/P&gt;&lt;P&gt;0004kj&lt;/P&gt;&lt;P&gt;000gh4&lt;/P&gt;&lt;P&gt;000000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried both :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;padded &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;charvar&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;best6&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;z6&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;and&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;xx = cats(repeat('0',6-length(x)-1), x);&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;cats somewhere is fine and somewhere is giving the error :&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"unknown func CATS and cannot be accessed" but with CATS i am getting the desired output&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;With the first thing only numeric values are getting populated with eading zeros rest are being changed to 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please give me a better format or an alternative for CATS/X/T/Q&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 22:08:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358360#M84179</guid>
      <dc:creator>sayanapex06</dc:creator>
      <dc:date>2017-05-12T22:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358361#M84180</link>
      <description>&lt;P&gt;i need a format to add leading zeros to alphanumeric character and numeric data and if data is 6 character it has to be same&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 22:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358361#M84180</guid>
      <dc:creator>sayanapex06</dc:creator>
      <dc:date>2017-05-12T22:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358362#M84181</link>
      <description>&lt;P&gt;This works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    length A $6. ;
    infile datalines;
    input A $;
    b = catt(repeat('0',6-length(a)-1),a);
datalines;
81
91
81
aaaaaa
bbbbbb
cfg014
456asd
4kj
gh4
0
;
run;

proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to build yourself a custom function see the answer to this similar question here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/SAS-Formats-Is-it-possible-to-create-a-format-to-add-leading/td-p/310451" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/SAS-Formats-Is-it-possible-to-create-a-format-to-add-leading/td-p/310451&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 22:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358362#M84181</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-12T22:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358364#M84183</link>
      <description>&lt;P&gt;error :Function CATT unknown and cannot be accessed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 22:22:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358364#M84183</guid>
      <dc:creator>sayanapex06</dc:creator>
      <dc:date>2017-05-12T22:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358366#M84185</link>
      <description>&lt;P&gt;What version of SAS are you using?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Post your code and log.&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 22:25:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358366#M84185</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-12T22:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358377#M84189</link>
      <description>&lt;P&gt;This works for sure, no errors in my log.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if length(a) = 6 then b=a;
else b=catt(repeat('0', 6-length(a)-1, a);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 May 2017 23:07:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358377#M84189</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-12T23:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358384#M84195</link>
      <description>&lt;P&gt;Why am I getting :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FUNCTION CATT unknown or cannot be accessed error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What are the reasons please tell me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 23:15:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358384#M84195</guid>
      <dc:creator>sayanapex06</dc:creator>
      <dc:date>2017-05-12T23:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358385#M84196</link>
      <description>&lt;P&gt;&lt;STRONG&gt;What version of SAS are you using?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Post your code and log.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 23:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358385#M84196</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-12T23:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358387#M84198</link>
      <description>&lt;P&gt;I am using SAS in zOS i.e in mainframe.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I am trying the syntax :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;xx = cats(repeat('0',6-length(x)-1), x);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It works fine when I am reading from datalines and giving any random inputs. It is working perfectly fine without any errors.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But when I am reading a ~ delimitted file and there is a field which is of $6. And when I am trying to conver that field to&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;xx = cats(repeat('0',6-length(x)-1), x);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I get the error :&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;FUCNTION CATS not found or cannot be accessed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But when I am reading from datalines I am not getting the error..&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 23:24:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358387#M84198</guid>
      <dc:creator>sayanapex06</dc:creator>
      <dc:date>2017-05-12T23:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358388#M84199</link>
      <description>&lt;P&gt;1. Either you have an error before that's causing the issue with the function&lt;/P&gt;
&lt;P&gt;2. Your SAS version is old and doesn't support the CATT functions.&lt;/P&gt;
&lt;P&gt;3. It's not available in Z/OS for some reason - seems unlikely but possible.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. It's not available via pass through if you're using that&lt;/P&gt;
&lt;P&gt;5. You're not using SAS but using a different system (WPS) that doesn't support it&lt;/P&gt;
&lt;P&gt;6. Something else that you're likely not conveying in the question here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Roll a dice I guess.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 23:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358388#M84199</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-12T23:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358389#M84200</link>
      <description>&lt;P&gt;can you explain point 4&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 23:30:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358389#M84200</guid>
      <dc:creator>sayanapex06</dc:creator>
      <dc:date>2017-05-12T23:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358390#M84201</link>
      <description>&lt;P&gt;If you can't use CATT() function then use something else.&lt;/P&gt;
&lt;P&gt;You could use the SUBSTRN() function.&lt;/P&gt;
&lt;P&gt;Or you could use REVERSE(), TRIM() and SUBSTR().&lt;/P&gt;
&lt;P&gt;Or make up your own.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
  input a $6. ;
cards;
123
abcdef
;

data want ;
 set x;
 b=substrn('000000',1,6-length(a))||a;
 c=reverse(substr(reverse(trim(a))||'000000',1,6));
 put (_all_) (=$quote.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 May 2017 23:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358390#M84201</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-05-12T23:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358392#M84203</link>
      <description>&lt;P&gt;Hi tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;could you show me the output of the program&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 00:08:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358392#M84203</guid>
      <dc:creator>sayanapex06</dc:creator>
      <dc:date>2017-05-13T00:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358413#M84211</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    input A $80.;
datalines;
81
1034
91
A46
6HJ
AAAAAA
F39000DSUG08CSDF85000000
;
run;
data want;
 set test;
 length new want $ 6;
 do i=1 to length(a) by 6;
  new=substr(a,i,6);
  want=translate(right(new),'0',' ');
  output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 May 2017 03:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358413#M84211</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-13T03:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358414#M84212</link>
      <description>&lt;P&gt;Output from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;64
65 data want ;
66 set x;
67 b=substrn('000000',1,6-length(a))||a;
68 c=reverse(substr(reverse(trim(a))||'000000',1,6));
69 put (_all_) (=$quote.);
70 run;
&amp;nbsp;
a="123" b="000123" c="000123"
a="abcdef" b="abcdef" c="abcdef"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sat, 13 May 2017 03:37:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358414#M84212</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-13T03:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Adding leading zeros to numeric,alphanumeric and character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358421#M84214</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/120272"&gt;@sayanapex06&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;If you need a format then that's what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;already&amp;nbsp;provided in the link she posted earlier. Have you looked into it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here a code sample based on&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*1*/
proc fcmp outlib=work.functions.myfunc;
  function leadZ(instring $) $;
    instring=left(instring);
    l=length(instring);
    if l &amp;gt;= 6 then
      do;
        outstring=instring;
      end;
    else 
      do;
        r=5-length(instring);
        outstring = repeat('0',r)||trim(instring);
      end;
    return (outstring);
  endsub;
run;

/*2*/
options cmplib=work.functions;

proc format;
  value $leadZ other=[leadZ()];
run;

data have;
  input a_have $char20.;
  datalines;
91
  81
aaaaaa
bbbbbb
cfg014
456asd
4kj
gh4
 12345678910
;
run;

data want;
  set have;
  a_want1=put(a_have,$leadZ20.);
  a_want2=put(a_have,$leadZ6.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8865iF241759126DEA633/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 06:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-leading-zeros-to-numeric-alphanumeric-and-character/m-p/358421#M84214</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-05-13T06:17:32Z</dc:date>
    </item>
  </channel>
</rss>

