<?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 to Merge these tables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77153#M22362</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you just need to add leading zeros?&amp;nbsp; This DATA step creates a second variable with leading zeros.&lt;/P&gt;&lt;P&gt;data have(drop=len);&lt;/P&gt;&lt;P&gt;length x1 x2 $9;&lt;/P&gt;&lt;P&gt;input x1 $;&lt;/P&gt;&lt;P&gt;x2='000000000';&lt;/P&gt;&lt;P&gt;len=length(x1);&lt;/P&gt;&lt;P&gt;substr(x2,9-len+1) = x1;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;1234&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Mar 2013 17:46:24 GMT</pubDate>
    <dc:creator>ArtC</dc:creator>
    <dc:date>2013-03-14T17:46:24Z</dc:date>
    <item>
      <title>How to Merge these tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77150#M22359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Table1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Table2&lt;/P&gt;&lt;P&gt;NUM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NUM&lt;/P&gt;&lt;P&gt;12345678&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 012345678&lt;/P&gt;&lt;P&gt;&amp;nbsp; 9876543&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 009876543&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 16:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77150#M22359</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-03-14T16:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to Merge these tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77151#M22360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are the columns numeric or character?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 17:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77151#M22360</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2013-03-14T17:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to Merge these tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77152#M22361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What do you mean by 'MERGE'?&amp;nbsp; What is your hoped for result?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 17:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77152#M22361</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2013-03-14T17:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to Merge these tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77153#M22362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you just need to add leading zeros?&amp;nbsp; This DATA step creates a second variable with leading zeros.&lt;/P&gt;&lt;P&gt;data have(drop=len);&lt;/P&gt;&lt;P&gt;length x1 x2 $9;&lt;/P&gt;&lt;P&gt;input x1 $;&lt;/P&gt;&lt;P&gt;x2='000000000';&lt;/P&gt;&lt;P&gt;len=length(x1);&lt;/P&gt;&lt;P&gt;substr(x2,9-len+1) = x1;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;1234&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 17:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77153#M22362</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2013-03-14T17:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to Merge these tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77154#M22363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Let's break down the code a bit:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First I am going to initialize X2 to all zeros.&lt;/P&gt;&lt;P&gt;x2='000000000';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We will need to know how many characters are in X1 (there are other ways to count characters, but this is easy).&lt;/P&gt;&lt;P&gt;len=length(x1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SUBSTR function can be used on either the left or right of the equal sign.&amp;nbsp; When it is used on the right it extracts characters from the string.&amp;nbsp; When it is used on the left it inserts characters.&amp;nbsp; Here we want to insert the characters contained in X1 into X2.&amp;nbsp; This replaces corresponding preloaded zeros.&amp;nbsp; The second argument (9-len+1) tells SUBSTR where to start the insertion.&amp;nbsp; I could have written this argument as 10-len.&lt;/P&gt;&lt;P&gt;substr(x2,9-len+1) = x1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hopefully X2 can now be used to match the variables in the other data set that already have the leading zeros.&amp;nbsp; I am assuming that the numbers themselves are some kind of coded value.&amp;nbsp; It is, therefore, probably safer to leave them as character strings.&amp;nbsp; Merging using numeric values can have some unintended consequences (there are rounding and storage issues).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 18:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77154#M22363</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2013-03-14T18:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to Merge these tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77155#M22364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To left fill '0's, aside from ArtC's igneous left-substr() approach (BTW, Art and all, are there any other functions can be applied like this? I can't recall any), here is another more conventional approach (borrowing Art's data):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;length x1 x2 $9;&lt;/P&gt;&lt;P&gt;input x1 $;&lt;/P&gt;&lt;P&gt;x2=put(input(x1,best.),z9.);&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;1234&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 20:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77155#M22364</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-03-14T20:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to Merge these tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77156#M22365</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So why convert back to character after converting to numeric?&amp;nbsp; Why not just stop at&lt;/P&gt;&lt;P&gt;x2=input(x1,best.);&lt;/P&gt;&lt;P&gt;and do the merge using numeric values?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That's the basis for the proc sql statement discussed above.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 21:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77156#M22365</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2013-03-14T21:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to Merge these tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77157#M22366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, according to OP's post (3rd one from top), both x1 and x2 are char.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 21:38:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Merge-these-tables/m-p/77157#M22366</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-03-14T21:38:43Z</dc:date>
    </item>
  </channel>
</rss>

