<?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: Numeric Concatination with Leading zeros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Concatination-with-Leading-zeros/m-p/233593#M42670</link>
    <description>&lt;P&gt;I would also add a delimiter between the two columns when concatenating as done in below code for "key2"&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  Field1=0001234;
  Field2=0005678;
  output;
run;

data want;
  set have;
  length key1 $14 key2 $15;
  key1=put(field1,z7.)||put(field2,z7.);
  key2=catx('|',put(field1,z7.),put(field2,z7.));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 07 Nov 2015 01:56:07 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2015-11-07T01:56:07Z</dc:date>
    <item>
      <title>Numeric Concatination with Leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Concatination-with-Leading-zeros/m-p/233592#M42669</link>
      <description>&lt;P&gt;Hi Everyone!&lt;/P&gt;&lt;P&gt;I was working on this data that has two numeric data fields with leading zeros. I wanted to concatinate without dropping the leading zeros to create a unique key. Can you guys help me please?&lt;/P&gt;&lt;P&gt;Field1=0001234&lt;/P&gt;&lt;P&gt;Field2=0005678&lt;/P&gt;&lt;P&gt;New Data Field will be: New_Field=00012340005678&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this, but keeps dropping the leading zeros from both data fields before it concatinates&lt;/P&gt;&lt;P&gt;DATA want&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;SET have&lt;/P&gt;&lt;P&gt;New_Field=((LEFT(Field1)) || (LEFT(Field2));&lt;/P&gt;&lt;P&gt;RUN&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;Thanks Guys!&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;Luke.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2015 01:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Concatination-with-Leading-zeros/m-p/233592#M42669</guid>
      <dc:creator>maseffa82</dc:creator>
      <dc:date>2015-11-07T01:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Concatination with Leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Concatination-with-Leading-zeros/m-p/233593#M42670</link>
      <description>&lt;P&gt;I would also add a delimiter between the two columns when concatenating as done in below code for "key2"&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  Field1=0001234;
  Field2=0005678;
  output;
run;

data want;
  set have;
  length key1 $14 key2 $15;
  key1=put(field1,z7.)||put(field2,z7.);
  key2=catx('|',put(field1,z7.),put(field2,z7.));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Nov 2015 01:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Concatination-with-Leading-zeros/m-p/233593#M42670</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-11-07T01:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Concatination with Leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Concatination-with-Leading-zeros/m-p/233597#M42673</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;'s answer is correct. The fields probably have a format applied, but when you concatenate them it's using the unformatted value. &lt;BR /&gt;&lt;BR /&gt;catx or catt are two good options to concatenate variables.</description>
      <pubDate>Sat, 07 Nov 2015 02:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Concatination-with-Leading-zeros/m-p/233597#M42673</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-07T02:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Concatination with Leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Concatination-with-Leading-zeros/m-p/233598#M42674</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/61232"&gt;@maseffa82&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Everyone!&lt;/P&gt;
&lt;P&gt;I was working on this data that has two numeric data fields with leading zeros. I wanted to concatinate without dropping the leading zeros to create a unique key. Can you guys help me please?&lt;/P&gt;
&lt;P&gt;Field1=0001234&lt;/P&gt;
&lt;P&gt;Field2=0005678&lt;/P&gt;
&lt;P&gt;New Data Field will be: New_Field=00012340005678&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried this, but keeps dropping the leading zeros from both data fields before it concatinates&lt;/P&gt;
&lt;P&gt;DATA want&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT color="#000000"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;SET have&lt;/P&gt;
&lt;P&gt;New_Field=((LEFT(Field1)) || (LEFT(Field2));&lt;/P&gt;
&lt;P&gt;RUN&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT color="#000000"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT color="#000000"&gt;Thanks Guys!&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT color="#000000"&gt;Luke.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Numbers cannot store&amp;nbsp;eading zeros. If they are displayed that way then it is because they have a format attached to them.&lt;/P&gt;
&lt;P&gt;If you concatenate them you will create a character variable, which could store the leading zeros. &amp;nbsp;So this statement will create a character variable with 14 digits (characters).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;charid = put(field1,Z7.)||put(field2,Z7.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if you want to create a new numeric variable then just use multiply one value by a power of 10 and add the other one. You can then attach a format to have the leading zeros appear.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;numid = field1*10**7 + field2 ;
format numid Z14. ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2015 03:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Concatination-with-Leading-zeros/m-p/233598#M42674</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-11-07T03:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Concatination with Leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Concatination-with-Leading-zeros/m-p/233599#M42675</link>
      <description>&lt;P&gt;It makes no sense for numeric field with leading zero in actual data. Numeric field with leading zero you see is due to format, when you concatenate, you could not get what you want. If you need to keep new field with leading zero, you have to convert numeric field to char field.&lt;BR /&gt;data have;&lt;BR /&gt;Field1=1234;&lt;BR /&gt;Field2=5678;&lt;BR /&gt;new_field1=cats(put(field1,z7.),put(field2,z7.));&lt;BR /&gt;new_field2=input(new_field1,14.);&lt;BR /&gt;format field1 z7. field2 z7. new_field2 z14.;&lt;BR /&gt;output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc contents data=have;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2015 03:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Concatination-with-Leading-zeros/m-p/233599#M42675</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2015-11-07T03:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Concatination with Leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Concatination-with-Leading-zeros/m-p/233615#M42682</link>
      <description>Thanks guys! It worked!</description>
      <pubDate>Sat, 07 Nov 2015 09:32:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Concatination-with-Leading-zeros/m-p/233615#M42682</guid>
      <dc:creator>maseffa82</dc:creator>
      <dc:date>2015-11-07T09:32:10Z</dc:date>
    </item>
  </channel>
</rss>

