<?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 zeros in front of values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/353282#M82454</link>
    <description>&lt;P&gt;It's the logic of DO WHILE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After the first time through the loop a single zero has been added:&amp;nbsp; 0123&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DO WHILE condition is still true, since the length is now 4.&amp;nbsp; So the loop executes a second time, adding another zero:&amp;nbsp; 00123&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the DO WHILE condition is false, so the loop ends.&lt;/P&gt;</description>
    <pubDate>Tue, 25 Apr 2017 16:39:15 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-04-25T16:39:15Z</dc:date>
    <item>
      <title>Adding zeros in front of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/352975#M82348</link>
      <description>&lt;P&gt;I have a dataset with values like this (it is a character with length of 7)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8519iD4B8E306B18115A6/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="AFF.PNG" title="AFF.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is this - IF the actual value is less than 5 digits, add zeros to the beginning of the value until it is 5 digits long.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 18:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/352975#M82348</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2017-04-24T18:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Adding zeros in front of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/352982#M82351</link>
      <description>&lt;DIV&gt;&lt;STRONG&gt;&lt;SPAN&gt;data&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt; want;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;set&lt;/SPAN&gt;&lt;SPAN&gt; have;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; length(var)&amp;lt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;/STRONG&gt; &lt;SPAN&gt;then&lt;/SPAN&gt;&lt;SPAN&gt; var=reverse(substr(strip( reverse(var))||&lt;/SPAN&gt;&lt;SPAN&gt;'00000000'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;) );&lt;/SPAN&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;SPAN&gt;run&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Naveen Srinivasan&lt;/DIV&gt;</description>
      <pubDate>Mon, 24 Apr 2017 19:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/352982#M82351</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-04-24T19:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: Adding zeros in front of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/352984#M82353</link>
      <description>&lt;P&gt;A simple loop could do it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do while (length(var) &amp;lt; 5);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var = '0' || var;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 19:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/352984#M82353</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-24T19:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Adding zeros in front of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/352985#M82354</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test_data1; 
length studyid $50;
input studyid $;  
cards;
543
243
15967
26484143651
5442
124
1
23
4423
;
run;

data test_data1;
set test_data1;
if length(studyid) &amp;lt; 5 THEN DO;
studyid = repeat('0',5-length(studyid)) || studyid;
END;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Apr 2017 19:19:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/352985#M82354</guid>
      <dc:creator>thomp7050</dc:creator>
      <dc:date>2017-04-24T19:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Adding zeros in front of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/353161#M82421</link>
      <description>&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;the&lt;/P&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;variable is numeric so use formate option&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test_data1; 
input studyid ; 
format studyid z8.; 
cards;
543
243
15967
26484143651
5442
124
1
23
4423
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;formate zw.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;w means total how many digits you want with zeros&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 12:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/353161#M82421</guid>
      <dc:creator>bollurajkumar</dc:creator>
      <dc:date>2017-04-25T12:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Adding zeros in front of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/353248#M82446</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;How exactly does this work? How is the data step looping back to keep adding zeros - I get that there's the while condition, but say I have 123 which needs &amp;nbsp;2 zeros in front of it. Data step will go through the loop to put the first 0 in front. How does it come back to that observation to add another zero? I know it has to do with the condition and the PDV, just not sure of the details...&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 15:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/353248#M82446</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2017-04-25T15:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Adding zeros in front of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/353282#M82454</link>
      <description>&lt;P&gt;It's the logic of DO WHILE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After the first time through the loop a single zero has been added:&amp;nbsp; 0123&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DO WHILE condition is still true, since the length is now 4.&amp;nbsp; So the loop executes a second time, adding another zero:&amp;nbsp; 00123&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the DO WHILE condition is false, so the loop ends.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 16:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-zeros-in-front-of-values/m-p/353282#M82454</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-25T16:39:15Z</dc:date>
    </item>
  </channel>
</rss>

