<?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 data step equivalent of SQL left join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/data-step-equivalent-of-SQL-left-join/m-p/331966#M74679</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does this data step code represent sql equivalent below?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;merge a (in = a) b (in = b) c (in = c);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;if a or b;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;select a*,b*,c*&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;from a&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; left join b on a.id = b.id&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; left join c on b.id = c.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 12 Feb 2017 15:42:05 GMT</pubDate>
    <dc:creator>SAS_inquisitive</dc:creator>
    <dc:date>2017-02-12T15:42:05Z</dc:date>
    <item>
      <title>data step equivalent of SQL left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-equivalent-of-SQL-left-join/m-p/331966#M74679</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does this data step code represent sql equivalent below?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;merge a (in = a) b (in = b) c (in = c);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;if a or b;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;select a*,b*,c*&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;from a&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; left join b on a.id = b.id&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; left join c on b.id = c.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 15:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-equivalent-of-SQL-left-join/m-p/331966#M74679</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2017-02-12T15:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: data step equivalent of SQL left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-equivalent-of-SQL-left-join/m-p/331970#M74681</link>
      <description>&lt;P&gt;No. If it isn't a many to many merge/join then I think the following would be the same:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want1;
   merge a (in = a) b (in = b) c (in = c);
   by id;
   if a and (a or b);
run;
 
proc sql;
   create table want2 as
   select a.*,b.*,c.*
     from a
        left join b on a.id = b.id
        left join c on b.id = c.id
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 16:41:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-equivalent-of-SQL-left-join/m-p/331970#M74681</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-12T16:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: data step equivalent of SQL left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-equivalent-of-SQL-left-join/m-p/331972#M74682</link>
      <description>&lt;P&gt;The short answer is no.&amp;nbsp; But SAS is a data analysis system, and your question is an excellent opportunity to use it. Here is such a&amp;nbsp;test:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; a b c;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&amp;nbsp; do&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; id=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; a b c;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; b c;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; c;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&amp;nbsp; end&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; mergeabc;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&amp;nbsp; merge&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; a b c;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&amp;nbsp; by&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; id;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&amp;nbsp; create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; want &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;as&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&amp;nbsp; select&lt;/FONT&gt; &lt;FONT color="#008080" face="Courier New"&gt;a.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;*,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New"&gt;b.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;*,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New"&gt;c.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;*&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&amp;nbsp; from&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; a&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; left&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;join&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; b &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;on&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; a.id = b.id&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; left&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;join&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; c &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;on&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; b.id = c.id;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 16:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-equivalent-of-SQL-left-join/m-p/331972#M74682</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-12T16:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: data step equivalent of SQL left join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-equivalent-of-SQL-left-join/m-p/331996#M74686</link>
      <description>&lt;P&gt;Why do you ask?&lt;/P&gt;
&lt;P&gt;And, strictly, you never be sure if a SQL query and a data step have the same result. It all comes down to the data at hand, and what your desired&amp;nbsp;outcome is. SO I think the general answer to all SQL vs data step question should be no. On of the most obvious things is that SQL does not&amp;nbsp;preserve the original sort order.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 20:34:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-equivalent-of-SQL-left-join/m-p/331996#M74686</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-02-12T20:34:19Z</dc:date>
    </item>
  </channel>
</rss>

