<?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 tables in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/JOIN-tables/m-p/464694#M30049</link>
    <description>&lt;P&gt;If you have several records in t2 that fulfill the join condition for a given record in t1, you will get multiple entries. Make sure before joining that you have only one record in t2 for every comgrp in t1.&lt;/P&gt;</description>
    <pubDate>Thu, 24 May 2018 11:33:18 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-05-24T11:33:18Z</dc:date>
    <item>
      <title>JOIN tables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/JOIN-tables/m-p/464691#M30048</link>
      <description>&lt;P&gt;I have this Code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;CREATE&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;TABLE&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; WORK.SNAP_1 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AS&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; t1.text,&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;t1.Date_C01,&lt;/P&gt;&lt;P&gt;t1.Date_C02,&lt;/P&gt;&lt;P&gt;t1.ContryA,&lt;/P&gt;&lt;P&gt;t1.Area,&lt;/P&gt;&lt;P&gt;t1.MONTH,&lt;/P&gt;&lt;P&gt;t1.Revision,&lt;/P&gt;&lt;P&gt;t1.COMGRP,&lt;/P&gt;&lt;P&gt;t2.Group,&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;t2.Top_Exports&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;t2.Top_Imports&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; WORK.SNAP t1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;INNER&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;JOIN&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; WORK.COM_CODES t2 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;ON&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (t1.COMGRP = t2.COMGRP);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are 128037 records in T1 (Snap) and because I just want to add additional records to this table I&amp;nbsp;am doing an INNER JOIN&lt;/P&gt;&lt;P&gt;However, the resulting table SNAP_1 has more records&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas why this is so? and how can I correct it?&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 11:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/JOIN-tables/m-p/464691#M30048</guid>
      <dc:creator>IOF</dc:creator>
      <dc:date>2018-05-24T11:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: JOIN tables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/JOIN-tables/m-p/464694#M30049</link>
      <description>&lt;P&gt;If you have several records in t2 that fulfill the join condition for a given record in t1, you will get multiple entries. Make sure before joining that you have only one record in t2 for every comgrp in t1.&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 11:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/JOIN-tables/m-p/464694#M30049</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-24T11:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: JOIN tables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/JOIN-tables/m-p/464719#M30050</link>
      <description>&lt;P&gt;Inner Join brings all the records that are common in both the tables. You may have multiple records per&amp;nbsp;&lt;SPAN&gt;COMGRP in your&amp;nbsp;COM_CODES table. You may need to bring only one record from the table your joining.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Check this example:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tableA;
Format  Order_date mmddyy10.;
input id item $ Order_date mmddyy10.;
datalines;
1 A 05/24/2018
2 A 05/25/2018
;
run;

data tableB;
Format  del_date mmddyy10.;
input id item $ del_date mmddyy10.;
datalines;
1 A 05/30/2018
1 A 05/26/2018
;
run;

PROC SQl;
create table want as
select a.id,a.item,a.Order_date,b.del_date
from tableA a
	inner join TableB b on (a.id=b.id and a.item=b.item)
	;
quit;
/* Joining tableA with TableB having only one record per group */
PROC SQl;
create table want as
select a.id,a.item,a.Order_date,b.del_date
from tableA a
	inner join (select * 
					from TableB 
						group  by id,item  
						having max(del_date)=del_date) b on (a.id=b.id and a.item=b.item)
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 12:41:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/JOIN-tables/m-p/464719#M30050</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-05-24T12:41:16Z</dc:date>
    </item>
  </channel>
</rss>

