<?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: Padding Front of Character value with 0's in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/611177#M178082</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;This ended up being the only one that worked with my real data actually. Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 11 Dec 2019 22:30:32 GMT</pubDate>
    <dc:creator>Time_Looper47</dc:creator>
    <dc:date>2019-12-11T22:30:32Z</dc:date>
    <item>
      <title>Padding Front of Character value with 0's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/610848#M177965</link>
      <description>&lt;P&gt;I have a very simple problem. I'm looking to pad the front of a character value with 0's until it hits a certain length (8). And I do NOT want to use the "z." format. I figured it would be simple like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hello_world;
infile datalines;
input ID $;
cards;
12
234
3456
;;
run;

data hallow_world;
  set hello_world;
  do while(length(ID)&amp;lt;8);
  cats('0',ID);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but is throwing an error. Seems like the only part I have wrong is what is within the do while loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So please help - someone can I do this within a "do while"? Also tried like this new_var=cats('0',ID); but it seemed to go into an infinite loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Most of the solutions I see online already use the "z." format and I want to avoid this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 21:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/610848#M177965</guid>
      <dc:creator>Time_Looper47</dc:creator>
      <dc:date>2019-12-10T21:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Padding Front of Character value with 0's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/610853#M177969</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293046"&gt;@Time_Looper47&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simple arithmetic&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data hello_world;
infile datalines;
input ID $;
cards;
12
234
3456
;;
run;

data want;
set hello_world;
length want_id $8;
want_id=cats(repeat('0',7-length(id)),id);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Dec 2019 21:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/610853#M177969</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-10T21:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: Padding Front of Character value with 0's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/610856#M177972</link>
      <description>&lt;P&gt;Or if you want to LOOP&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data hello_world;
infile datalines;
input ID $;
cards;
12
234
3456
;;
run;

data want;
set hello_world;
length want_id $8;
want_id=id;
do while(length(want_id)&amp;lt;8);
 want_id=cats('0',want_id);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Dec 2019 22:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/610856#M177972</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-10T22:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Padding Front of Character value with 0's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/610857#M177973</link>
      <description>&lt;P&gt;No need for a loop. How about this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id_zero = cats(substr("00000000", 1, 8-length(id)), id);&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;Hope this helps,&lt;/P&gt;
&lt;P&gt;-- Jan.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 22:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/610857#M177973</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2019-12-10T22:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Padding Front of Character value with 0's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/610858#M177974</link>
      <description>&lt;P&gt;If you make ID a numeric variable, this is simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hello_world;
infile datalines;
input ID;
format id z8.;
cards;
12
234
3456
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Dec 2019 22:12:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/610858#M177974</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-10T22:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: Padding Front of Character value with 0's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/610950#M178018</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data hello_world;
infile datalines;
input ID $;
cards;
12
234
3456
;;
run;

data want;
set hello_world;
length want_id $8;
want_id=id;
want_id=translate(right(want_id),'0',' ');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Dec 2019 11:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/610950#M178018</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-11T11:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: Padding Front of Character value with 0's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/611177#M178082</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;This ended up being the only one that worked with my real data actually. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2019 22:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/611177#M178082</guid>
      <dc:creator>Time_Looper47</dc:creator>
      <dc:date>2019-12-11T22:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Padding Front of Character value with 0's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/612031#M178505</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_ID="00000000";
substr(new_id,9-length(id))=id;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit :&amp;nbsp; If some ids have leading blanks :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;substr(new_id,9-length(strip(id)))=strip(id);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Dec 2019 15:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Padding-Front-of-Character-value-with-0-s/m-p/612031#M178505</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-12-16T15:08:12Z</dc:date>
    </item>
  </channel>
</rss>

