<?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: join two tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/join-two-tables/m-p/407138#M99194</link>
    <description>&lt;P&gt;You can do the join in SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as select a.*
from have1 a, have2 b
where index(a.primkey,b.primkey) = 1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For a data step merge, you have to create a new variable in have1 that fits the key of have2.&lt;/P&gt;</description>
    <pubDate>Wed, 25 Oct 2017 06:34:07 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-10-25T06:34:07Z</dc:date>
    <item>
      <title>join two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/join-two-tables/m-p/407133#M99192</link>
      <description>&lt;P&gt;I have two tables&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table 1 has Primary Key column&amp;nbsp; whose value are&lt;/P&gt;
&lt;P&gt;10000_John&lt;/P&gt;
&lt;P&gt;10001_Andrew&lt;/P&gt;
&lt;P&gt;10002_Sam&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table2 has Primary Key whose value are&lt;/P&gt;
&lt;P&gt;10000&lt;/P&gt;
&lt;P&gt;10001&lt;/P&gt;
&lt;P&gt;10002&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have to join both the tables based on Primary key values&lt;/P&gt;
&lt;P&gt;Can I join them directly without manipulating any value in table 1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 05:57:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/join-two-tables/m-p/407133#M99192</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2017-10-25T05:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: join two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/join-two-tables/m-p/407137#M99193</link>
      <description>&lt;P&gt;Please post your example data as data steps, so we can recreate the data with copy/paste and submit.&lt;/P&gt;
&lt;P&gt;Use the proper subwindow for the code, see &lt;A href="https://communities.sas.com/t5/help/faqpage/faq-category-id/posting" target="_blank"&gt;https://communities.sas.com/t5/help/faqpage/faq-category-id/posting&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 06:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/join-two-tables/m-p/407137#M99193</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-25T06:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: join two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/join-two-tables/m-p/407138#M99194</link>
      <description>&lt;P&gt;You can do the join in SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as select a.*
from have1 a, have2 b
where index(a.primkey,b.primkey) = 1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For a data step merge, you have to create a new variable in have1 that fits the key of have2.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 06:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/join-two-tables/m-p/407138#M99194</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-25T06:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: join two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/join-two-tables/m-p/407150#M99195</link>
      <description>&lt;P&gt;I tried it but its not working&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have1;
length ID $20.;
input ID $ age;
datalines;
10000_John 25
10001_Andrew 24
10002_Sam 22
;

data have2;
length ID $20.;
input ID $ marks1 marks2;
datalines;
10000 75 78
10001 58 89
10002 85 73
;

proc sql;
create table want as select a.id, a.age,b.marks1, b.marks2
from have1 a, have2 b
where index(a.id,b.id) = 1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2017 07:57:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/join-two-tables/m-p/407150#M99195</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2017-10-25T07:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: join two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/join-two-tables/m-p/407153#M99196</link>
      <description>&lt;P&gt;Note that in my example, the shorter key variable was defined according to the length of its values. No sense in wasting space.&lt;/P&gt;
&lt;P&gt;If you have badly defined key variables (something to avoid, for obvious reasons), use the trim() function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as select a.id, a.age,b.marks1, b.marks2
from have1 a, have2 b
where index(a.id,trim(b.id)) = 1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Keep in mind that comparison functions like index() or find() will take the blanks with which overlong variables are padded into account.&lt;/P&gt;
&lt;P&gt;See Maxim 46.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 08:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/join-two-tables/m-p/407153#M99196</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-25T08:18:58Z</dc:date>
    </item>
  </channel>
</rss>

