<?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: syntax for a left join in SAS, not in the context of proc sql? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756126#M238679</link>
    <description>&lt;P&gt;Basically there isn't, because SQL works different when a many-to-many relationship is encountered.&lt;/P&gt;
&lt;P&gt;A DATA step can only replicate a left or right join when there is either a one-to-one, one-to-many or many-to-one relationship.&lt;/P&gt;
&lt;P&gt;Once that is verified, read the documentation of the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lestmtsref/n1i8w2bwu1fn5kn1gpxj18xttbb0.htm" target="_blank" rel="noopener"&gt;MERGE Statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jul 2021 06:07:40 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-07-23T06:07:40Z</dc:date>
    <item>
      <title>syntax for a left join in SAS, not in the context of proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756073#M238650</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;Would would be the context left and right join in SAS without using in proc sql?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Blue blue&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 22:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756073#M238650</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-07-22T22:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: syntax for a left join in SAS, not in the context of proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756079#M238655</link>
      <description>It is merge.&lt;BR /&gt;you can read about it here: &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1i8w2bwu1fn5kn1gpxj18xttbb0.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1i8w2bwu1fn5kn1gpxj18xttbb0.htm&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 22 Jul 2021 22:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756079#M238655</guid>
      <dc:creator>Rydhm</dc:creator>
      <dc:date>2021-07-22T22:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: syntax for a left join in SAS, not in the context of proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756085#M238661</link>
      <description>&lt;P&gt;You add dataset option IN= to each data set to identify if the current observation comes from the desired set. The select for output those that you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dummy code:&lt;/P&gt;
&lt;PRE&gt;Data want;
   merge data1 (in=inone)
              data2 (in=intwo)
   ;
   by keyvariable;
  /*in a given data step likely only want one of the following
    for most cases.
  */
  /* select records where data1 contributed*/
  if inone;
  /* or select records where data2 contributed*/
  if intwo;
  /* or select records where both data1 and data2*/
  if inone and intwo;
  /* select records from data1 that had no match in data2*/
  if inone and not intwo;
run;&lt;/PRE&gt;
&lt;P&gt;The IN variables are basically boolean: 1/0 for Yes/no so can be used in if statements. (Or summed to identify how many data sets contributed to given record since a MERGE statement can have many data sets ).&lt;/P&gt;
&lt;P&gt;However the Merge is still not the same as a "join on" when by values are duplicated in both sets.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 22:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756085#M238661</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-22T22:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: syntax for a left join in SAS, not in the context of proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756126#M238679</link>
      <description>&lt;P&gt;Basically there isn't, because SQL works different when a many-to-many relationship is encountered.&lt;/P&gt;
&lt;P&gt;A DATA step can only replicate a left or right join when there is either a one-to-one, one-to-many or many-to-one relationship.&lt;/P&gt;
&lt;P&gt;Once that is verified, read the documentation of the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lestmtsref/n1i8w2bwu1fn5kn1gpxj18xttbb0.htm" target="_blank" rel="noopener"&gt;MERGE Statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 06:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756126#M238679</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-23T06:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: syntax for a left join in SAS, not in the context of proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756383#M238781</link>
      <description>&lt;P&gt;Thanks for sending the link.&lt;/P&gt;
&lt;P&gt;It is very hard to understand from this document. I have read it several times!&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 06:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756383#M238781</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-07-24T06:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: syntax for a left join in SAS, not in the context of proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756385#M238783</link>
      <description>&lt;P&gt;For an easy entry into the documentation, start with the examples first. Copy the code and run it, then play around with it.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 06:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756385#M238783</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-24T06:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: syntax for a left join in SAS, not in the context of proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756413#M238806</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;pointed out, if you have a 1:many, many:1, or 1:1 for every key value, then a MERGE statement can easily work like a left join.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But many-to-many takes more effort, and use of a hash object.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;

  set right (in=inR)  left (in=inL);
  by key;

  if _n_=1 then do;
    declare hash r (dataset:'right (obs=0)',multidata:'Y');
      r.definekey('key');
      r.definedata(all:'Y');
      r.definedone();
  end;
  if first.key then r.clear();

  if inR then r.add();
  if inL ;


  if r.num_items=0 then output;
  else do rc=r.find() by 0 until (r.find_next()^=0);
    output;
  end;
  call missing(of _all_);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Basically, for each KEY, all the right-side observations are read first and loaded into a hash object in memory.&amp;nbsp; Then for each subsequent left observation, the program iterates through the hash object, retrieving values from the right-side and outputting for each iteration.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 17:08:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756413#M238806</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-07-24T17:08:57Z</dc:date>
    </item>
    <item>
      <title>Re: syntax for a left join in SAS, not in the context of proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756425#M238811</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Basically, for each KEY, all the right-side observations are read first and loaded into a hash object in memory.&amp;nbsp; Then for each subsequent left observation, the program iterates through the hash object, retrieving values from the right-side and outputting for each iteration.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does this&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;set right (in=inR)  left (in=inL);
  by key;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;determine which table should be read first?&lt;/P&gt;
&lt;P&gt;If we had:&lt;/P&gt;
&lt;P&gt;set Left (in=inL) right(in=inR)&lt;/P&gt;
&lt;P&gt;Is the top reads the right table first even if it is the second table in a row?&lt;/P&gt;
&lt;P&gt;Respectfully,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 20:42:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756425#M238811</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-07-24T20:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: syntax for a left join in SAS, not in the context of proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756526#M238873</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;&lt;SPAN&gt;Basically, for each KEY, all the right-side observations are read first and loaded into a hash object in memory.&amp;nbsp; Then for each subsequent left observation, the program iterates through the hash object, retrieving values from the right-side and outputting for each iteration.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does this&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;set right (in=inR)  left (in=inL);
  by key;&lt;/LI-CODE&gt;
&lt;P&gt;determine which table should be read first?&lt;/P&gt;
&lt;P&gt;If we had:&lt;/P&gt;
&lt;P&gt;set Left (in=inL) right(in=inR)&lt;/P&gt;
&lt;P&gt;Is the top reads the right table first even if it is the second table in a row?&lt;/P&gt;
&lt;P&gt;Respectfully,&lt;/P&gt;
&lt;P&gt;blueblue&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is one of those questions that can well be answered by&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Examining the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p00hxg3x8lwivcn1f0e9axziw57y.htm" target="_self"&gt;Documentation on the SET statement&lt;/A&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; Take notice of examples 1: concatenating data sets, and 2: interleaving data sets.&lt;BR /&gt;&lt;BR /&gt;and/or&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;Running some tests - one of the great features of learning any programming language or programming tool like SAS.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More generally, since you want to do a left join, you first want to load the RIGHT data into memory, so that it can be repeatedly and inexpensively looped over for each su7bsequent matching LEFT observation.&amp;nbsp; This in turn means you have to read the RIGHT prior to the LEFT, in order to put it in memory.&amp;nbsp; Thus "set right left".&amp;nbsp; The opposite ("set left right") would yield NO data from RIGHT, since it isn't in memory when processing the LEFT dataset.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jul 2021 18:19:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-a-left-join-in-SAS-not-in-the-context-of-proc-sql/m-p/756526#M238873</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-07-25T18:19:20Z</dc:date>
    </item>
  </channel>
</rss>

