<?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: Join datasets by group in sql in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746519#M80656</link>
    <description>&lt;P&gt;Left or Right join.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this previous questions for a good diagram (bottom) and reference to a paper that has more details.&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-equiv-of-Merge-If-A-or-B/td-p/255720" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-equiv-of-Merge-If-A-or-B/td-p/255720&lt;/A&gt;&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/99650"&gt;@xyxu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How to implement the following in proc sql?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = set1; by x, y; run;
proc sort data = set2; by x, y; run;

data set3;
merge set1 (in = a) set2 (in = b);
by x y;
if a and not b;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am trying to do this by group, and the group identifier is commonly available in set1 and set2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Jun 2021 17:18:10 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-06-08T17:18:10Z</dc:date>
    <item>
      <title>Join datasets by group in sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746507#M80653</link>
      <description>&lt;P&gt;How to implement the following in proc sql?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = set1; by x, y; run;
proc sort data = set2; by x, y; run;

data set3;
merge set1 (in = a) set2 (in = b);
by x y;
if a and not b;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am trying to do this by group, and the group identifier is commonly available in set1 and set2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 16:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746507#M80653</guid>
      <dc:creator>xyxu</dc:creator>
      <dc:date>2021-06-08T16:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: Join datasets by group in sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746509#M80654</link>
      <description>&lt;P&gt;Are there variables in common between set1 and set2 other than X and Y?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data step merge will "update" common variable other than the by variables and if you need/want that behavior we need to know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW your sort syntax is incorrect. No commas in a BY statement&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 16:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746509#M80654</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-08T16:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: Join datasets by group in sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746517#M80655</link>
      <description>Yes, there are common variables between the two sets. Let's call them variable z. In the sql, set2 is only used to kick out observations in set1.&lt;BR /&gt;You are right that my proc sort should not include commas in the by statement.</description>
      <pubDate>Tue, 08 Jun 2021 17:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746517#M80655</guid>
      <dc:creator>xyxu</dc:creator>
      <dc:date>2021-06-08T17:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: Join datasets by group in sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746519#M80656</link>
      <description>&lt;P&gt;Left or Right join.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this previous questions for a good diagram (bottom) and reference to a paper that has more details.&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-equiv-of-Merge-If-A-or-B/td-p/255720" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-equiv-of-Merge-If-A-or-B/td-p/255720&lt;/A&gt;&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/99650"&gt;@xyxu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How to implement the following in proc sql?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = set1; by x, y; run;
proc sort data = set2; by x, y; run;

data set3;
merge set1 (in = a) set2 (in = b);
by x y;
if a and not b;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am trying to do this by group, and the group identifier is commonly available in set1 and set2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 17:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746519#M80656</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-08T17:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: Join datasets by group in sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746532#M80657</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table set3 as 
  select *
  from
  set1 a left join set2 b
  on a.x=b.x and a.y=b.y
  where a.x ne b.x and a.y ne b.y;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note: I used * in select clause coz I am lazy to type and that will throw a warning because of ambiguity. However, you could type the list of variables that you need appropriately.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 17:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746532#M80657</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-06-08T17:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Join datasets by group in sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746543#M80658</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table set3 as
  select t1.*
  from set1 t1 left join set2 t2
  on t1.x = t2.x and t1.y = t2.y
  where missing(t2.x) or missing(t2.y)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Jun 2021 18:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746543#M80658</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-08T18:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Join datasets by group in sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746550#M80659</link>
      <description>Why should we use "and" in the where clause, instead of "or" ? My goal is to find all obs in set1 that does not have any match in set2 in terms of a pair of x and y.</description>
      <pubDate>Tue, 08 Jun 2021 18:58:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746550#M80659</guid>
      <dc:creator>xyxu</dc:creator>
      <dc:date>2021-06-08T18:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Join datasets by group in sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746566#M80660</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;My goal is to find all obs in set1 that does not have any match in set2 in terms of a pair of x and y."--&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/99650"&gt;@xyxu&lt;/a&gt;&amp;nbsp; Yeah OR is just fine too&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;on a.x=b.x and a.y=b.y&lt;BR /&gt;where a.x ne b.x or a.y ne b.y;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 19:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/746566#M80660</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-06-08T19:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Join datasets by group in sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/747327#M80674</link>
      <description>&lt;P&gt;Just use set operator?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n0vo2lglyrnexwn14emi8m0jqvrj.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n0vo2lglyrnexwn14emi8m0jqvrj.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 13:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/747327#M80674</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-06-11T13:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Join datasets by group in sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/750702#M80720</link>
      <description>&lt;P&gt;&lt;EM&gt;I&amp;nbsp; suggest you stick with data step merge (in comparison to proc SQL).&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;The already have a&amp;nbsp; code that&amp;nbsp; needs some modifications as follows and you will be nearing your goal.&lt;BR /&gt;&lt;/EM&gt;As suggested by&amp;nbsp;@&lt;A class="trigger-hovercard" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884" target="_blank"&gt;ballardw &lt;/A&gt;&amp;nbsp;make corrections to the sort syntax.&lt;/P&gt;
&lt;P&gt;In addition rename the common variables (other than by variables) in one of the datasets.&lt;/P&gt;
&lt;P&gt;You may have to do home post processing to the merged dataset to get exactly what you want,&lt;/P&gt;
&lt;P&gt;but you can easily achieve your objective of purging the rows of dataset2 from dataset1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jun 2021 17:52:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-datasets-by-group-in-sql/m-p/750702#M80720</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-06-27T17:52:28Z</dc:date>
    </item>
  </channel>
</rss>

