<?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: left join and inner join in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/left-join-and-inner-join-in-proc-sql/m-p/799062#M314164</link>
    <description>&lt;P&gt;If you want control use data step instead of SQL.&lt;/P&gt;
&lt;P&gt;For example you might MERGE the two dataset by the key variable and use the IN= dataset option to be able to track which dataset contributed to this observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you have two datasets named ONE and TWO and the key variable is named ID then the code might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge one(in=in1) two(in=in2);
  by id;
  if in1 and in2 then source='BOTH';
  else if in1 then source='ONE ';
  else source='TWO';
  unique=first.id;
run;

proc summary data=want;
  class source;
  var unique;
  output out=summary N=COUNT sum(unique)=UNIQUE ;
run;

proc print data=summary;
   var source count unique;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 28 Feb 2022 03:34:28 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-02-28T03:34:28Z</dc:date>
    <item>
      <title>left join and inner join in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/left-join-and-inner-join-in-proc-sql/m-p/799027#M314143</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;I have 64 rows and I need to find them in a bigger data set. Here, my inquiry is about the logic that I have applied.&lt;/P&gt;
&lt;P&gt;I did a left outer join with missing on the second dataset and I was able to find those rows that exist in the first/left dataset, but it doesn't exist in the second/right dataset. The result came 4 rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I did inner join between first and second dataset with Distinct values and came 54 rows.&lt;/P&gt;
&lt;P&gt;If I do without distinct, the result is 169 rows.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;54+4 equal to 58 and deduct it from 64, we have 6 rows left, which I don't know what is going about them.&lt;/P&gt;
&lt;P&gt;Can we say since we put distinct, we removed duplicates, in fact those 6 rows are among those 54 rows, they are just taken away by Distinct because they are duplicates.&lt;/P&gt;
&lt;P&gt;Here, I am looking for logic. I need to know the way I elaborate it is correct. I need to present it to my boss.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Blue&amp;amp;Blue&lt;/P&gt;</description>
      <pubDate>Sun, 27 Feb 2022 23:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/left-join-and-inner-join-in-proc-sql/m-p/799027#M314143</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-02-27T23:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: left join and inner join in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/left-join-and-inner-join-in-proc-sql/m-p/799033#M314147</link>
      <description>&lt;P&gt;How many of the 64 are distinct?&lt;/P&gt;
&lt;P&gt;What do you mean by distinct?&amp;nbsp; Normally in SQL that means unique observations.&amp;nbsp; Two observations could have the same value of the key variable but still be unique because they have different values of other variables.&lt;/P&gt;</description>
      <pubDate>Sun, 27 Feb 2022 23:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/left-join-and-inner-join-in-proc-sql/m-p/799033#M314147</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-27T23:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: left join and inner join in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/left-join-and-inner-join-in-proc-sql/m-p/799052#M314159</link>
      <description>Hello,&lt;BR /&gt;Thanks for the reply,&lt;BR /&gt;Then if the join values are same but they have different values in other variables, that means the observations are unique. 54 are unique out of 64.&lt;BR /&gt;Regards,&lt;BR /&gt;Blue &amp;amp; Blue</description>
      <pubDate>Mon, 28 Feb 2022 02:48:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/left-join-and-inner-join-in-proc-sql/m-p/799052#M314159</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-02-28T02:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: left join and inner join in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/left-join-and-inner-join-in-proc-sql/m-p/799062#M314164</link>
      <description>&lt;P&gt;If you want control use data step instead of SQL.&lt;/P&gt;
&lt;P&gt;For example you might MERGE the two dataset by the key variable and use the IN= dataset option to be able to track which dataset contributed to this observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you have two datasets named ONE and TWO and the key variable is named ID then the code might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge one(in=in1) two(in=in2);
  by id;
  if in1 and in2 then source='BOTH';
  else if in1 then source='ONE ';
  else source='TWO';
  unique=first.id;
run;

proc summary data=want;
  class source;
  var unique;
  output out=summary N=COUNT sum(unique)=UNIQUE ;
run;

proc print data=summary;
   var source count unique;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Feb 2022 03:34:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/left-join-and-inner-join-in-proc-sql/m-p/799062#M314164</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-28T03:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: left join and inner join in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/left-join-and-inner-join-in-proc-sql/m-p/799074#M314173</link>
      <description>&lt;P&gt;Hello Tom,&lt;/P&gt;
&lt;P&gt;Thanks for the code.&lt;/P&gt;
&lt;P&gt;Can you explain about class and source?&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;proc summary data=want;
  class source;
  var unique;
  output out=summary N=COUNT sum(unique)=UNIQUE ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blue&amp;amp;blue&lt;/P&gt;</description>
      <pubDate>Mon, 28 Feb 2022 04:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/left-join-and-inner-join-in-proc-sql/m-p/799074#M314173</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-02-28T04:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: left join and inner join in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/left-join-and-inner-join-in-proc-sql/m-p/799075#M314174</link>
      <description>&lt;P&gt;SOURCE is the variable name.&lt;/P&gt;
&lt;P&gt;CLASS is a common SAS statement that is supported in various ways by a lot of SAS procedure.&amp;nbsp; It basically is for telling the procedure to group the data by the levels of that variable.&lt;/P&gt;
&lt;P&gt;For more information read the documentation on PROC SUMMARY (also known as PROC MEANS).&lt;/P&gt;</description>
      <pubDate>Mon, 28 Feb 2022 04:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/left-join-and-inner-join-in-proc-sql/m-p/799075#M314174</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-28T04:38:33Z</dc:date>
    </item>
  </channel>
</rss>

