<?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: How do I pad a character variable with leading zeroes using PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307098#M270597</link>
    <description>&lt;P&gt;Well, I say they "could" be right in certain circumstances, but its very dependant on scenario and a wide ranging statement of SQL &amp;gt; datastep at merging is misleading at best.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;B and C refer to variables in the output dataset, it takes the form of&lt;/P&gt;
&lt;P&gt;&amp;lt;logical statement&amp;gt; as &amp;lt;new_variable&amp;gt;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;lt;variable from contributing table&amp;gt; as &amp;lt;new_variable&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you run the code in SAS you will see the output.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Oct 2016 12:41:41 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-10-25T12:41:41Z</dc:date>
    <item>
      <title>How do I pad a character variable with leading zeroes using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307057#M270592</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that contains various numbers stored in a character format i.e.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;123456&lt;/P&gt;&lt;P&gt;7890&lt;/P&gt;&lt;P&gt;23&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to pad each of these values to so that each string is 16 characters long using a PROC SQL statement i.e.&lt;/P&gt;&lt;P&gt;0000000000123456&lt;/P&gt;&lt;P&gt;0000000000007890&lt;/P&gt;&lt;P&gt;0000000000000023&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have tried so far without much success:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;SELECT FORMAT (X, &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'0000000000000000000'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;FROM Table;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assistance would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2016 08:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307057#M270592</guid>
      <dc:creator>MattSan</dc:creator>
      <dc:date>2016-10-25T08:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I pad a character variable with leading zeroes using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307059#M270593</link>
      <description>&lt;P&gt;There are many ways, concatenation, changing to number and then back again are two for example:&lt;/P&gt;
&lt;PRE&gt;data want;
  a="123456";
  b=cats(repeat("0",20-lengthn(a)),a);
  c=put(input(a,best.),z20.);
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Oct 2016 08:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307059#M270593</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-25T08:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I pad a character variable with leading zeroes using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307060#M270594</link>
      <description>&lt;P&gt;Thank you however I was looking for a PROC SQL solution if possible? I need a PROC SQL version in order to possibly increase the processing speed on a large dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2016 08:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307060#M270594</guid>
      <dc:creator>MattSan</dc:creator>
      <dc:date>2016-10-25T08:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I pad a character variable with leading zeroes using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307064#M270595</link>
      <description>&lt;P&gt;Firstly, have you hard evidence that using proc sql will increase the processing speed? &amp;nbsp;I can certainly pull out some posts which show SQL usage on large datasets to be far more resource consuming. &amp;nbsp;Never restrict yourself to one technology.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, most datastep statement can be moved into a proc sql - of course if its passthrough then its a different matter - so:&lt;/P&gt;
&lt;PRE&gt;data have;
  a="123456";
run;                                                                                

proc sql;
  create table WANT as
  select  A,
          cats(repeat("0",20-lengthn(A)),A) as B,
          put(input(A,best.),z20.) as C
  from    HAVE;
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Oct 2016 08:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307064#M270595</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-25T08:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I pad a character variable with leading zeroes using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307093#M270596</link>
      <description>&lt;P&gt;Thank you for your response. I am still fairly new to SAS and therefore I am not certain of the processing overhead of some data steps vs PROC SQL however I have been told by my colleagues that using data step "merge" vs a SQL "join" procedure is much slower. I would like to mark your answer as the solution however I am not sure what variables "B" and "C" refer to? Please could you perhaps&amp;nbsp;clarify this?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2016 12:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307093#M270596</guid>
      <dc:creator>MattSan</dc:creator>
      <dc:date>2016-10-25T12:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I pad a character variable with leading zeroes using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307098#M270597</link>
      <description>&lt;P&gt;Well, I say they "could" be right in certain circumstances, but its very dependant on scenario and a wide ranging statement of SQL &amp;gt; datastep at merging is misleading at best.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;B and C refer to variables in the output dataset, it takes the form of&lt;/P&gt;
&lt;P&gt;&amp;lt;logical statement&amp;gt; as &amp;lt;new_variable&amp;gt;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;lt;variable from contributing table&amp;gt; as &amp;lt;new_variable&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you run the code in SAS you will see the output.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2016 12:41:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307098#M270597</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-25T12:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I pad a character variable with leading zeroes using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307108#M270598</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/111855"&gt;@MattSan&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you however I was looking for a PROC SQL solution if possible? I need a PROC SQL version in order to possibly increase the processing speed on a large dataset.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PROC SQL will &lt;U&gt;not&lt;/U&gt; speed up the processing; unless your dataset resides in a remote RDBMS that has a lot more computing power than your SAS host, where SQL pass-through will have a noticeable effect.&lt;/P&gt;
&lt;P&gt;In pure SAS, SQL is at best just as fast as a data step merge. And often considerably (up to several orders of magnitude) slower.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2016 12:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307108#M270598</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-25T12:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I pad a character variable with leading zeroes using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307847#M270599</link>
      <description>&lt;P&gt;My dataset does reside in a remote RDBMS&amp;nbsp;and the extra effort to sort the data&amp;nbsp;before merging the datasets is unwarranted.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2016 06:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-pad-a-character-variable-with-leading-zeroes-using-PROC/m-p/307847#M270599</guid>
      <dc:creator>MattSan</dc:creator>
      <dc:date>2016-10-28T06:44:54Z</dc:date>
    </item>
  </channel>
</rss>

