<?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: Proc Sql Left Join is exploding in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-is-exploding/m-p/562125#M157444</link>
    <description>&lt;P&gt;Something like this *might* work around your issue, depending on your data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table WRDS_CIK6
  as select c5.*, ca.GVKEY as COMP_GVKEY
  from WRDS_CIK5                                   c5 
         left join 
       (select unique CIK, GVKEY from WRDS_CIK_A)  ca
         on c5.CIK = ca.CIK;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 May 2019 23:27:26 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-05-28T23:27:26Z</dc:date>
    <item>
      <title>Proc Sql Left Join is exploding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-is-exploding/m-p/562104#M157427</link>
      <description>&lt;P&gt;I use Proc Sql to Left Join in SAS all the time. But the last few months, I feel like the same code I always used makes the dataset explode instead of actually left join. I know this crazy. I am still just using SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example,&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table wrds_cik6&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as select *, b.gvkey as comp_gvkey&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from wrds_cik5 as a left join wrds_cik_a as b&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on a.cik = b.cik;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;wrds_cik5 only has about 180,000 observations. Yet, it returns 300,000,000 observations after this code. Why is it exploding? (I looked on this board for info to an almost identical question earlier, and the answer was, "left join has always done this.")&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 20:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-is-exploding/m-p/562104#M157427</guid>
      <dc:creator>cadams47</dc:creator>
      <dc:date>2019-05-28T20:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Left Join is exploding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-is-exploding/m-p/562107#M157430</link>
      <description>&lt;P&gt;You likely have duplicate CIK records in each table. If you have 5 CIK in Table1 and 3 in Table2 after the left join you'll have 15 records. You likely need to add another filter to the join or someway to reduce those duplicates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115976"&gt;@cadams47&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I use Proc Sql to Left Join in SAS all the time. But the last few months, I feel like the same code I always used makes the dataset explode instead of actually left join. I know this crazy. I am still just using SAS 9.4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example,&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table wrds_cik6&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as select *, b.gvkey as comp_gvkey&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from wrds_cik5 as a left join wrds_cik_a as b&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on a.cik = b.cik;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;wrds_cik5 only has about 180,000 observations. Yet, it returns 300,000,000 observations after this code. Why is it exploding? (I looked on this board for info to an almost identical question earlier, and the answer was, "left join has always done this.")&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 20:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-is-exploding/m-p/562107#M157430</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-28T20:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Left Join is exploding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-is-exploding/m-p/562112#M157434</link>
      <description>&lt;P&gt;Just like Reeza said, it appears that you have duplicate values for the joined variable in at least one of the tables that you are joining.&lt;/P&gt;&lt;P&gt;Here is some code to show this happening:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.have1;
	col1 = 1;
	col2 = 1;
	output;
	col1 = 2;
	col2 = 1;
	output;
	col1 = 3;
	col2 = 1;
	output;
run;

data work.have2;
	col1 = 1;
	col3 = 2;
	output;
	col1 = 2;
	col3 = 2;
	output;
	col1 = 4;
	col3 = 2;
	output;
run;


proc sql;
	create table work.want as 
		select *
			, b.col3
		from work.have1 as a
		left join work.have2 as b
			on a.col1 = b.col3
			;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Even though we are joining two tables with 3 rows each, the table created has 5 rows.&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 21:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-is-exploding/m-p/562112#M157434</guid>
      <dc:creator>Urban_Science</dc:creator>
      <dc:date>2019-05-28T21:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Left Join is exploding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-is-exploding/m-p/562117#M157439</link>
      <description>&lt;P&gt;Ahhh. You're right. I have multiple cik's from my &lt;STRONG&gt;right-side&lt;/STRONG&gt; table. Thank you both for the help.&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 21:58:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-is-exploding/m-p/562117#M157439</guid>
      <dc:creator>cadams47</dc:creator>
      <dc:date>2019-05-28T21:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Left Join is exploding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-is-exploding/m-p/562125#M157444</link>
      <description>&lt;P&gt;Something like this *might* work around your issue, depending on your data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table WRDS_CIK6
  as select c5.*, ca.GVKEY as COMP_GVKEY
  from WRDS_CIK5                                   c5 
         left join 
       (select unique CIK, GVKEY from WRDS_CIK_A)  ca
         on c5.CIK = ca.CIK;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 23:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-is-exploding/m-p/562125#M157444</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-28T23:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Left Join is exploding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-is-exploding/m-p/562187#M157467</link>
      <description>&lt;P&gt;When I run into this issue, I use this construct in SQL.&amp;nbsp; There are other ways in base SAS such as SORT or FREQ, but I usually revert to this construct because I work directly in the RDBMS a lot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table test as
   select cik, count(0) as count
   from wrds_cik5
   group by cik
   having count(0) &amp;gt; 1;
quit;

proc sql;
   create table test as
   select cik, count(0) as count
   from wrds_cik_a
   group by cik
   having count(0) &amp;gt; 1;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output should be zero records, meaning your keys (group by variables) uniquely identify each record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a LEFT JOIN, you can have dups in the left table, but if you have dups in the right table, your target table will "explode".&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 08:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Left-Join-is-exploding/m-p/562187#M157467</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-29T08:38:03Z</dc:date>
    </item>
  </channel>
</rss>

