<?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: Add trailing zeros to character data to fill up maximum length in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329479#M62541</link>
    <description>&lt;P&gt;Why do you have characters in it? &amp;nbsp;This makes the problem far more complicated than necessary. &amp;nbsp;Instead of just putting the number to Zx. format, you now need to check length and repeat and concat:&lt;/P&gt;
&lt;PRE&gt;data have;
  have="33p.";
  want=cats(have,repeat("0",5-lengthn(have)));
run;&lt;/PRE&gt;</description>
    <pubDate>Thu, 02 Feb 2017 15:48:42 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-02-02T15:48:42Z</dc:date>
    <item>
      <title>Add trailing zeros to character data to fill up maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329466#M62539</link>
      <description>&lt;P&gt;I would like to add trailing zeros to character data in the following way - to fill up to maximum of 7 characters:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;133P. -&amp;gt; 133P.00&lt;/P&gt;&lt;P&gt;39B.. -&amp;gt; 39B..00&lt;/P&gt;&lt;P&gt;22EG.-&amp;gt; 22EG.00&lt;/P&gt;&lt;P&gt;R0832 -&amp;gt; R083200&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 15:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329466#M62539</guid>
      <dc:creator>Dani08</dc:creator>
      <dc:date>2017-02-02T15:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Add trailing zeros to character data to fill up maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329477#M62540</link>
      <description>&lt;P&gt;Length new_var $7;&lt;/P&gt;
&lt;P&gt;new_var = Catt(old_var, '0000000');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add 7 zeroes to the end, but assign a length of 7. This causes the variable to truncate after 7th char meaning you get the variable plus the 0s, as desired.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 15:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329477#M62540</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-02T15:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Add trailing zeros to character data to fill up maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329479#M62541</link>
      <description>&lt;P&gt;Why do you have characters in it? &amp;nbsp;This makes the problem far more complicated than necessary. &amp;nbsp;Instead of just putting the number to Zx. format, you now need to check length and repeat and concat:&lt;/P&gt;
&lt;PRE&gt;data have;
  have="33p.";
  want=cats(have,repeat("0",5-lengthn(have)));
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Feb 2017 15:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329479#M62541</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-02T15:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: Add trailing zeros to character data to fill up maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329483#M62542</link>
      <description>&lt;P&gt;The following should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  input have $;
  want='0000000';
  substr(want,1,length(have))=substr(have,1,length(have));
  cards;
133P.
39B..
22EG.
R0832
;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 15:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329483#M62542</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-02T15:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Add trailing zeros to character data to fill up maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329489#M62544</link>
      <description>&lt;P&gt;It is necessary to have characters in this variable. They are medical read codes.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 16:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329489#M62544</guid>
      <dc:creator>Dani08</dc:creator>
      <dc:date>2017-02-02T16:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Add trailing zeros to character data to fill up maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329493#M62545</link>
      <description>Thank you for your reply.&lt;BR /&gt;&lt;BR /&gt;is it important where I put the length statement?&lt;BR /&gt;If I place it before the set statement, the new_var is blank,&lt;BR /&gt;if I place it after the set statement, I get 7 trailing '0's at the end...&lt;BR /&gt;&lt;BR /&gt;please let me know if I am doing something wrong.</description>
      <pubDate>Thu, 02 Feb 2017 16:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329493#M62545</guid>
      <dc:creator>Dani08</dc:creator>
      <dc:date>2017-02-02T16:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Add trailing zeros to character data to fill up maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329496#M62546</link>
      <description>&lt;P&gt;Put the length statement before the set statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried my suggested code. The following contains it and a slight variant of&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;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  input old_var $;
  cards;
133P.
39B..
22EG.
R0832
;

data want;
  Length new_var1 new_var2 $7;
  set have;
  new_var1='0000000';
  substr(new_var1,1,length(old_var))=substr(old_var,1,length(old_var));
  new_var2 = substr(Catt(old_var, '0000000'),1,7);
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 17:00:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329496#M62546</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-02T17:00:41Z</dc:date>
    </item>
    <item>
      <title>Re: Add trailing zeros to character data to fill up maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329499#M62547</link>
      <description>Is there a way to carry this out for the whole dataset? I have 1500+ observations...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 02 Feb 2017 16:36:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329499#M62547</guid>
      <dc:creator>Dani08</dc:creator>
      <dc:date>2017-02-02T16:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: Add trailing zeros to character data to fill up maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329502#M62548</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/119906"&gt;@Dani08&lt;/a&gt; wrote:&lt;BR /&gt;Thank you for your reply.&lt;BR /&gt;&lt;BR /&gt;is it important where I put the length statement?&lt;BR /&gt;If I place it before the set statement, the new_var is blank,&lt;BR /&gt;if I place it after the set statement, I get 7 trailing '0's at the end...&lt;BR /&gt;&lt;BR /&gt;please let me know if I am doing something wrong.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you include a $ sign? If not then your new_var was numeric and wouldn't hold the result of a character value very well.&lt;/P&gt;
&lt;PRE&gt;data want;
   length New_var $ 7;
   set yourdataset;
   New_var = substr(translate(code,'0',''),1,7);
run;&lt;/PRE&gt;
&lt;P&gt;Another approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 16:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329502#M62548</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-02T16:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Add trailing zeros to character data to fill up maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329509#M62549</link>
      <description>&lt;P&gt;Not sure what your question is. The above approaches are all designed to do the task for all of the records in the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 17:02:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329509#M62549</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-02T17:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: Add trailing zeros to character data to fill up maximum length</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329510#M62550</link>
      <description>Thank you! I am new to SAS, sorry for the confusing questions. This solved my problem.</description>
      <pubDate>Thu, 02 Feb 2017 17:10:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-trailing-zeros-to-character-data-to-fill-up-maximum-length/m-p/329510#M62550</guid>
      <dc:creator>Dani08</dc:creator>
      <dc:date>2017-02-02T17:10:12Z</dc:date>
    </item>
  </channel>
</rss>

