<?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 Leading Zeroes and retain numeric format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Leading-Zeroes-and-retain-numeric-format/m-p/603363#M174811</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ln_no ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;21555555&lt;/P&gt;
&lt;P&gt;5544000&lt;/P&gt;
&lt;P&gt;6654444&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ln_no lt &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;17&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;THEN&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; LN_No = (input(ln_no, &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;best4.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;),&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;z17.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*if ln_no lt 17 THEN LN_No = substr(left(LN_Nbr_R),1,10.);*/&lt;/P&gt;
&lt;P&gt;/*if ln_no lt 17 THEN LN_No = substr(left(LN_Nbr_R),1,10.);*/&lt;/P&gt;
&lt;P&gt;/*if ln_no lt 17 THEN LN_No = put(ln_no, z10.);/*Ln_no = put(Account, z10.);*/&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ln_no started out as a numeric.&lt;/P&gt;
&lt;P&gt;Desired output is to have a 17 digit number with leading zeros.&amp;nbsp; The format should retain its numeric status&lt;/P&gt;
&lt;P&gt;Something like this&lt;/P&gt;
&lt;P&gt;0000000021555555&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see I have tried different pieces of code here.&lt;/P&gt;</description>
    <pubDate>Mon, 11 Nov 2019 21:28:12 GMT</pubDate>
    <dc:creator>Q1983</dc:creator>
    <dc:date>2019-11-11T21:28:12Z</dc:date>
    <item>
      <title>Leading Zeroes and retain numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-Zeroes-and-retain-numeric-format/m-p/603363#M174811</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ln_no ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;21555555&lt;/P&gt;
&lt;P&gt;5544000&lt;/P&gt;
&lt;P&gt;6654444&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ln_no lt &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;17&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;THEN&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; LN_No = (input(ln_no, &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;best4.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;),&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;z17.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*if ln_no lt 17 THEN LN_No = substr(left(LN_Nbr_R),1,10.);*/&lt;/P&gt;
&lt;P&gt;/*if ln_no lt 17 THEN LN_No = substr(left(LN_Nbr_R),1,10.);*/&lt;/P&gt;
&lt;P&gt;/*if ln_no lt 17 THEN LN_No = put(ln_no, z10.);/*Ln_no = put(Account, z10.);*/&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ln_no started out as a numeric.&lt;/P&gt;
&lt;P&gt;Desired output is to have a 17 digit number with leading zeros.&amp;nbsp; The format should retain its numeric status&lt;/P&gt;
&lt;P&gt;Something like this&lt;/P&gt;
&lt;P&gt;0000000021555555&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see I have tried different pieces of code here.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 21:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-Zeroes-and-retain-numeric-format/m-p/603363#M174811</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2019-11-11T21:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Leading Zeroes and retain numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-Zeroes-and-retain-numeric-format/m-p/603367#M174812</link>
      <description>&lt;P&gt;If your variable is actually a loan number with as many as 17&amp;nbsp;&lt;/P&gt;
&lt;P&gt;digits, then SAS can't hold that number accurately in a numeric variable. You need to store it as a character variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input @1 ln_no $12.;
  ln_no_new = repeat('0', 16 - length(ln_no) - 1) !! ln_no;
  put _all_; 
  datalines;
21555555
5544000
6654444
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 21:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-Zeroes-and-retain-numeric-format/m-p/603367#M174812</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-11-11T21:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Leading Zeroes and retain numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-Zeroes-and-retain-numeric-format/m-p/603372#M174813</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A bit of a problem with this offer is that REPEAT returns $200 by default, and so LN_NO_NEW will be $212. To avoid this, either length $17 has to be assigned to LN_NO_NEW beforehand or the $17. format should be applied to the result, like so:&lt;/P&gt;
&lt;PRE&gt;  ln_no_new = put (repeat('0', 16 - length(ln_no) - 1) !! ln_no, $17.) ;
&lt;/PRE&gt;
&lt;P&gt;But perhaps it's simpler (at least to me) to use:&lt;/P&gt;
&lt;PRE&gt;  ln_no_new = translate (put (ln_no, $17.-R), "0", "") ; 
&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 22:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-Zeroes-and-retain-numeric-format/m-p/603372#M174813</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-11-11T22:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: Leading Zeroes and retain numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-Zeroes-and-retain-numeric-format/m-p/603378#M174814</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp; - Good point. A LENGTH statement would probably be the most obvious solution for others to follow.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 22:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-Zeroes-and-retain-numeric-format/m-p/603378#M174814</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-11-11T22:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: Leading Zeroes and retain numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Leading-Zeroes-and-retain-numeric-format/m-p/603386#M174816</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp; - Or assign back to original variable having adjusted the INFORMAT to the required length:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input @1 ln_no $16.;
  ln_no = repeat('0', 16 - length(ln_no) - 1) !! ln_no;
  put _all_; 
  datalines;
21555555
5544000
6654444
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Nov 2019 22:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Leading-Zeroes-and-retain-numeric-format/m-p/603386#M174816</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-11-11T22:46:40Z</dc:date>
    </item>
  </channel>
</rss>

