<?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: A left join in a proc sql instead of merge? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759223#M239876</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;Can we use a proc sql and left join for this code below?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;
&lt;PRE&gt;data out.mydata;
merge thisdata(in=a) thatdata(in=b);
by hkey;
format find $15.;
if a and b then Find = 'Both';
if a and not b then Find = 'not_in_thisdata'
if a then output;
run;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So, you have a working data step, tested and giving the expected results. Why do you want to waste your time replacing it at all?&lt;/P&gt;</description>
    <pubDate>Wed, 04 Aug 2021 06:59:53 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2021-08-04T06:59:53Z</dc:date>
    <item>
      <title>A left join in a proc sql instead of merge?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759162#M239841</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;Can we use a proc sql and left join for this code below?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;
&lt;PRE&gt;data out.mydata;
merge thisdata(in=a) thatdata(in=b);
by hkey;
format find $15.;
if a and b then Find = 'Both';
if a and not b then Find = 'not_in_thisdata'
if a then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Aug 2021 22:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759162#M239841</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-08-03T22:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: A left join in a proc sql instead of merge?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759176#M239851</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;Can we use a proc sql and left join for this code below?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;
&lt;PRE&gt;data out.mydata;
merge thisdata(in=a) thatdata(in=b);
by hkey;
format find $15.;
if a and b then Find = 'Both';
if a and not b then Find = 'not_in_thisdata'
if a then output;
run;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If &lt;STRIKE&gt;(and only if)&lt;/STRIKE&gt;, for each unique HKEY value either have a one:one, many:one or a one:many match (i.e. no many:many matches), then yes you can reproduce the merge code you showed with a PROC SQL:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  create table out.mydata as
  select *, 
     case thatdata.hkey
       when . then "Not_in_thisdata"
       else "Both"
     end
     as find
  from thisdata left join thatdata
  on thisdata.hkey=thatdata.hkey;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But why?&amp;nbsp; If the data are already sorted, then the data step merge will be faster for large data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 12:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759176#M239851</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-08-04T12:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: A left join in a proc sql instead of merge?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759178#M239853</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;If (and only if), for each unique HKEY value either have a many:one or a one:many match (i.e. no many:many matches), then yes you can reproduce the merge code you showed with a PROC SQL&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;one:one is also a valid case for SQL to match a data step logic&lt;/P&gt;
&lt;P&gt;Another condition for the SQL shown to identify missing data in the right table is that the key is never missing in the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt; why?&amp;nbsp; If the data are already sorted, then the data step merge will be faster for large data sets.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I agree in principle. If the sort is validated, the difference should be minimal though as SQL will not re-sort.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sadly &lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/create-a-VALIDATESORT-data-set-option-to-validate-the-sort-order/idi-p/288038" target="_self"&gt;SAS forgot to be clever here and does not set this flag as it should except in a few cases&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 03:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759178#M239853</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-04T03:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: A left join in a proc sql instead of merge?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759188#M239858</link>
      <description>&lt;P&gt;All your questions about the different types of merge/join would be much faster, and much better, answered by your testing the syntaxes and examples you ask about. Doing is a much better way to learn than asking questions.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 03:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759188#M239858</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-04T03:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: A left join in a proc sql instead of merge?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759216#M239872</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Do we need to bring below code in? Because left join bring all from left table and all the matches from both tables.&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;  case thatdata.hkey
       when . then "Not_in_thisdata"
       else "Both"
     end
     as find&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Respectfully,&lt;/P&gt;
&lt;P&gt;Blublue&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 06:31:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759216#M239872</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-08-04T06:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: A left join in a proc sql instead of merge?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759218#M239873</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I did test it, but I couldn't figure it out. I need an assurance.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 06:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759218#M239873</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-08-04T06:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: A left join in a proc sql instead of merge?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759220#M239875</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; Do we need to bring below code in?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The code you show will identify records present in the left table and not present in the right table, provided the data does not contain missing key values.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 06:38:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759220#M239875</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-04T06:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: A left join in a proc sql instead of merge?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759223#M239876</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;Can we use a proc sql and left join for this code below?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;
&lt;PRE&gt;data out.mydata;
merge thisdata(in=a) thatdata(in=b);
by hkey;
format find $15.;
if a and b then Find = 'Both';
if a and not b then Find = 'not_in_thisdata'
if a then output;
run;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So, you have a working data step, tested and giving the expected results. Why do you want to waste your time replacing it at all?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 06:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759223#M239876</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-04T06:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: A left join in a proc sql instead of merge?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759234#M239884</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I did test it, but I couldn't figure it out. I need an assurance.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;lt;SNARK&amp;gt;&lt;/P&gt;
&lt;P&gt;If you tested it, and it worked, and you don't even trust your own test, then you need to pay a visit to a shrink.&lt;/P&gt;
&lt;P&gt;&amp;lt;/SNARK&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no better way in programming to verify a code than to test it. Trusting another person that took a casual glance is foolish at best.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you expect a trustworthy answer, we would need to test &lt;EM&gt;your whole code&lt;/EM&gt; against &lt;EM&gt;your whole data&lt;/EM&gt; in &lt;EM&gt;your environment&lt;/EM&gt;. And then we'd start charging you.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 07:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/759234#M239884</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-04T07:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: A left join in a proc sql instead of merge?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/760269#M240387</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried and I could view the result of both.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am clear on this one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;</description>
      <pubDate>Sun, 08 Aug 2021 18:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/760269#M240387</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-08-08T18:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: A left join in a proc sql instead of merge?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/760314#M240417</link>
      <description>&lt;P&gt;Please mark the most helpful answer as solution.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 05:52:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-left-join-in-a-proc-sql-instead-of-merge/m-p/760314#M240417</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-09T05:52:43Z</dc:date>
    </item>
  </channel>
</rss>

