<?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: multiple left join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/739440#M286610</link>
    <description>&lt;P&gt;If your datasets are large, then there is a good case for not using SQL at all.&amp;nbsp; SAS implementation of SQL (from what I recal) is that it is all done be loading and writing into intermediary tables, so when data gets larger then it takes longer to process.&lt;/P&gt;
&lt;P&gt;The question raised here was "how do I do xyz", not should I be doing "xyz".&amp;nbsp; IN case of big datasets I would set both sets of data together with a category defining which dataset of orign, then merge the two sets of data using a datastep merge, this would be the most efficient method to get the final result.&lt;/P&gt;</description>
    <pubDate>Thu, 06 May 2021 10:06:05 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2021-05-06T10:06:05Z</dc:date>
    <item>
      <title>multiple left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/480442#M286605</link>
      <description>&lt;P&gt;Hi all, I want to know how can join 2 tables to one tables by using left join. I have my patient cohort and want to join 2 other datasets to get more variables. The number of observations will remain the same just the variable number will increase.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code looks like this.. but it is incomplete. Is there a way I can use multiple left joins ?&lt;/P&gt;&lt;P&gt;Is there a way to combine both the dataset ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS. b.code in both the steps have different values for code, one is coming from dataset1 and the other is coming from dataset2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*LEFT JOIN TO GET CODES FROM DATASET1 */
proc sql ;
	create table _01_esrd_dial_codes as 
	select distinct a.*, b.code 
	from _01_pt as a
	left join DATASET1 as b 
	on a.enrolid = b.enrolid ;
quit ;

/*LEFT JOIN TO GET CODES FROM DATASET2 */
proc sql ;
	create table _01_JOIN2 as 
	select distinct a.*, b.code 
	from _01_pt as a
	left join DATASET2 as b 
	on a.enrolid = b.enrolid ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Jul 2018 14:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/480442#M286605</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-23T14:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: multiple left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/480461#M286606</link>
      <description>&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;proc sql ;
	create table _01_esrd_dial_codes as 
	select distinct a.*, b.code,c.code as c_code
	from _01_pt as a
	left join dataset1 as b 
	on a.enrolid = b.enrolid
        left join dataset2 as c
        on a.enrolid=c.enrolid;
quit;&lt;/PRE&gt;
&lt;P&gt;You can keep adding left or right of full joins on as much as you like up to about 20 something joins.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 14:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/480461#M286606</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-23T14:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: multiple left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/480466#M286607</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works but i also want to stack b.code and c_code. Is that possible in the same step as the left join&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 14:56:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/480466#M286607</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-23T14:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: multiple left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/480469#M286608</link>
      <description>&lt;P&gt;Yes.&amp;nbsp; I would do it like this, just clearer for me:&lt;/P&gt;
&lt;PRE&gt;proc sql ;
  create table _01_esrd_dial_codes as 
  select distinct a.*, &lt;BR /&gt;                  b.code
  from _01_pt as a
  left join (select enrolid,&lt;BR /&gt;                    code&lt;BR /&gt;             from   dataset1 
             union all &lt;BR /&gt;             select enrolid,&lt;BR /&gt;                    code&lt;BR /&gt;             from   dataset2) b&lt;BR /&gt;  on   a.enrolid=b.enrolid;
quit;&lt;/PRE&gt;
&lt;P&gt;Note that this assumes the same type in both dataset1 and 2.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 15:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/480469#M286608</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-23T15:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: multiple left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/739281#M286609</link>
      <description>I have a question regarding this piece of code. I find that if the datasets are large, combining two left joins in this way is much slower than separating them into two proc sqls. Does SAS form a Cartesian product of all three data sets, `_01_pt`, `dataset1`, and `dataset2` when executing this query?</description>
      <pubDate>Wed, 05 May 2021 17:21:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/739281#M286609</guid>
      <dc:creator>flcong</dc:creator>
      <dc:date>2021-05-05T17:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: multiple left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/739440#M286610</link>
      <description>&lt;P&gt;If your datasets are large, then there is a good case for not using SQL at all.&amp;nbsp; SAS implementation of SQL (from what I recal) is that it is all done be loading and writing into intermediary tables, so when data gets larger then it takes longer to process.&lt;/P&gt;
&lt;P&gt;The question raised here was "how do I do xyz", not should I be doing "xyz".&amp;nbsp; IN case of big datasets I would set both sets of data together with a category defining which dataset of orign, then merge the two sets of data using a datastep merge, this would be the most efficient method to get the final result.&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 10:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/739440#M286610</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2021-05-06T10:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: multiple left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/739497#M286611</link>
      <description>Thank you! I wasn't aware of the performance advantage of data merge over sql. I basically only use sql, for convenience. No wonder I feel SAS is slow.</description>
      <pubDate>Thu, 06 May 2021 14:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/739497#M286611</guid>
      <dc:creator>flcong</dc:creator>
      <dc:date>2021-05-06T14:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: multiple left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/835322#M330239</link>
      <description>Another nice thing about merge is that the code is succinct i.e. it requires a lot less typing than proc sql code.</description>
      <pubDate>Mon, 26 Sep 2022 21:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-left-join/m-p/835322#M330239</guid>
      <dc:creator>jjsingh04</dc:creator>
      <dc:date>2022-09-26T21:23:00Z</dc:date>
    </item>
  </channel>
</rss>

