<?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 leading zeros to a numeric field in a proc sql connect to teradata step in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-leading-zeros-to-a-numeric-field-in-a-proc-sql-connect-to/m-p/669972#M36453</link>
    <description>Search the page I linked above for a function to convert your number to a character. You tried CAST above and it's likely that.</description>
    <pubDate>Thu, 16 Jul 2020 20:05:24 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-07-16T20:05:24Z</dc:date>
    <item>
      <title>Add leading zeros to a numeric field in a proc sql connect to teradata step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-leading-zeros-to-a-numeric-field-in-a-proc-sql-connect-to/m-p/669960#M36450</link>
      <description>&lt;P&gt;Hello SAS Community,&lt;/P&gt;&lt;P&gt;Is there a way to pull a numeric field in a "proc sql; connect to teradata" step and add leading zeros at the same time? So I'd want to make this sort of translation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have ----&amp;gt; Want&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; -----&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;01&lt;/P&gt;&lt;P&gt;10&amp;nbsp; -----&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;11&amp;nbsp; -----&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;11&lt;/P&gt;&lt;P&gt;12&amp;nbsp; -----&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;12&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; -----&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;02&lt;/P&gt;&lt;P&gt;20&amp;nbsp; -----&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;/P&gt;&lt;P&gt;21&amp;nbsp; -----&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;21&lt;/P&gt;&lt;P&gt;22&amp;nbsp; -----&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;22&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I feel like I've been dancing around the solution using one of the cast, input, or put functions and the format of char(2), char2., z2., 'XX', or $char2. but I just can't seem to get the right combination to get it to work. I've tried all of the commented out combinations in the code below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
connect to teradata;
create table add_leading_zeros as select * from connection to teradata
( select distinct
/*&amp;nbsp; &amp;nbsp; &amp;nbsp;want_character = input(have_number,char2.)*/
/*&amp;nbsp; &amp;nbsp; &amp;nbsp;want_character = put(have_number,char2.)*/
/*&amp;nbsp; &amp;nbsp; &amp;nbsp;want_character = put(have_number,char(2))*/
/*&amp;nbsp; &amp;nbsp; &amp;nbsp;want_character = put(have_number,z2.)*/
/* &amp;nbsp; &amp;nbsp; cast(have_number as z2.)*/
/* &amp;nbsp; &amp;nbsp; cast(have_number as char('XX'))*/
/* &amp;nbsp; &amp;nbsp; cast(have_number as char(2))*/
/* &amp;nbsp; &amp;nbsp; cast(have_number as char2.)*/
/* &amp;nbsp; &amp;nbsp; cast(have_number as $char2.)*/
/* &amp;nbsp; &amp;nbsp; cast(have_number as '99')*/
/* &amp;nbsp; &amp;nbsp; have_number format $char2.*/
/* &amp;nbsp; &amp;nbsp; have_number format char2.*/
/* &amp;nbsp; &amp;nbsp; have_number format CHAR(2)*/
/* &amp;nbsp; &amp;nbsp; format(have_number,CHAR(2))*/
/* &amp;nbsp; &amp;nbsp; put(have_number,CHAR(2)) as want_character*/
/* &amp;nbsp; &amp;nbsp; input(have_number,CHAR(2)) as want_character*/
from database1.table1
order by 1
);
disconnect from teradata;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;I'm using SAS Enterprise Guide 9.4.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jul 2020 19:10:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-leading-zeros-to-a-numeric-field-in-a-proc-sql-connect-to/m-p/669960#M36450</guid>
      <dc:creator>proc_talk</dc:creator>
      <dc:date>2020-07-16T19:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: Add leading zeros to a numeric field in a proc sql connect to teradata step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-leading-zeros-to-a-numeric-field-in-a-proc-sql-connect-to/m-p/669962#M36451</link>
      <description>You're using pass through sql so you need to use a teradata function not a SAS function. I think it's lpad there.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;lpad(have_number, 2, '0') &lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://docs.teradata.com/reader/kmuOwjp1zEYg98JsB8fu_A/e5w8LujIQDlVmRSww2E27A" target="_blank"&gt;https://docs.teradata.com/reader/kmuOwjp1zEYg98JsB8fu_A/e5w8LujIQDlVmRSww2E27A&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Jul 2020 19:34:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-leading-zeros-to-a-numeric-field-in-a-proc-sql-connect-to/m-p/669962#M36451</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-16T19:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Add leading zeros to a numeric field in a proc sql connect to teradata step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-leading-zeros-to-a-numeric-field-in-a-proc-sql-connect-to/m-p/669970#M36452</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;! Your suggestion seems like what I'm after and it doesn't throw an error like all the other options I tried, however there is no change to the values, i.e. "1" is still "1" not "01". That documentation says that the source string should be character string or expression, do you think I need to nest changing the numeric values into a character string within the LPAD function? I'm not sure how to do that either...</description>
      <pubDate>Thu, 16 Jul 2020 20:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-leading-zeros-to-a-numeric-field-in-a-proc-sql-connect-to/m-p/669970#M36452</guid>
      <dc:creator>proc_talk</dc:creator>
      <dc:date>2020-07-16T20:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: Add leading zeros to a numeric field in a proc sql connect to teradata step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-leading-zeros-to-a-numeric-field-in-a-proc-sql-connect-to/m-p/669972#M36453</link>
      <description>Search the page I linked above for a function to convert your number to a character. You tried CAST above and it's likely that.</description>
      <pubDate>Thu, 16 Jul 2020 20:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-leading-zeros-to-a-numeric-field-in-a-proc-sql-connect-to/m-p/669972#M36453</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-16T20:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: Add leading zeros to a numeric field in a proc sql connect to teradata step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-leading-zeros-to-a-numeric-field-in-a-proc-sql-connect-to/m-p/669978#M36454</link>
      <description>&lt;P&gt;Looks like casting as a VARCHAR does the trick! Thanks for the nudge in the right direction&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;!&lt;/P&gt;&lt;P&gt;LPAD(cast(have_number as varchar(2)), 2, '0') as want_character&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jul 2020 20:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-leading-zeros-to-a-numeric-field-in-a-proc-sql-connect-to/m-p/669978#M36454</guid>
      <dc:creator>proc_talk</dc:creator>
      <dc:date>2020-07-16T20:18:17Z</dc:date>
    </item>
  </channel>
</rss>

