<?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: How to Do An Inner Join On Distinct Observations ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Do-An-Inner-Join-On-Distinct-Observations/m-p/592660#M169951</link>
    <description>&lt;P&gt;At a quick glance, your inline views are the issue. You are selecting the distinct &lt;STRONG&gt;Division_ID&lt;/STRONG&gt; but not not selecting any other columns, but you are referring to other columns in the SELECT clause from those in-line views.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You select &lt;STRONG&gt;B.MAT&lt;/STRONG&gt; from the main SELECT clause, which i'm guessing you want from the in-line view below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token statement"&gt;(Select&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;DISTINCT&lt;/SPAN&gt; DIVISION_ID      &lt;SPAN class="token keyword"&gt;FROM&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;ODS&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;R_M)&amp;nbsp;B&lt;CODE&gt;&lt;/CODE&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, you are not selecting the &lt;STRONG&gt;MAT&lt;/STRONG&gt; column in the in-line view above, but only the distinct &lt;STRONG&gt;Division_ID&lt;/STRONG&gt; is being returned. There is no &lt;STRONG&gt;B.MAT&lt;/STRONG&gt; column to select.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without seeing the data it's hard to give you a solution for your specific problem. But you might want to include the columns you are selecting in the main SELECT clause in your in-line views. Here is a new in-line view B that should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(Select DISTINCT DIVISION_ID, MAT, ART, MAC FROM ODS.R_M)&amp;nbsp;B&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now this will give you the unique combinations of &lt;STRONG&gt;Division_ID, MAT, ART&lt;/STRONG&gt; and &lt;STRONG&gt;MAC&lt;/STRONG&gt;. Not sure if that is what you are looking for. It might be easier to create separate views for those in-line views in their own queries, make sure those views are what you need, then use those to join. Example data would help.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Peter&lt;/P&gt;</description>
    <pubDate>Mon, 30 Sep 2019 13:26:32 GMT</pubDate>
    <dc:creator>Panagiotis</dc:creator>
    <dc:date>2019-09-30T13:26:32Z</dc:date>
    <item>
      <title>How to Do An Inner Join On Distinct Observations ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Do-An-Inner-Join-On-Distinct-Observations/m-p/592608#M169943</link>
      <description>&lt;P&gt;Hi Everyone.&lt;/P&gt;
&lt;P&gt;So , I want to do an Inner Join on distinct observations of other columns , the distinct would be performed on Division_ID from both B &amp;amp; C, but i'm not sure how i can do that , this is what i tried to do , and that obviously gave me an Error.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
Create Table INDICATORS as
select A.*, B.MAT, B.ART, B.MAC, C.ID_F as F_ID
from Cust A
inner join (Select DISTINCT DIVISION_ID&lt;BR /&gt;      FROM ODS.R_M )B
 on A.Division_ID = B.Division_ID
inner join (SELECT DISTINCT DIVISION_ID&lt;BR /&gt;       FROM ODS.Fam ) C
 on A.Division_ID = C.division_ID
;
Quit; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any Suggestion Would Be Much Appreciated , Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 10:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Do-An-Inner-Join-On-Distinct-Observations/m-p/592608#M169943</guid>
      <dc:creator>Midi</dc:creator>
      <dc:date>2019-09-30T10:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to Do An Inner Join On Distinct Observations ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Do-An-Inner-Join-On-Distinct-Observations/m-p/592660#M169951</link>
      <description>&lt;P&gt;At a quick glance, your inline views are the issue. You are selecting the distinct &lt;STRONG&gt;Division_ID&lt;/STRONG&gt; but not not selecting any other columns, but you are referring to other columns in the SELECT clause from those in-line views.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You select &lt;STRONG&gt;B.MAT&lt;/STRONG&gt; from the main SELECT clause, which i'm guessing you want from the in-line view below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token statement"&gt;(Select&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;DISTINCT&lt;/SPAN&gt; DIVISION_ID      &lt;SPAN class="token keyword"&gt;FROM&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;ODS&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;R_M)&amp;nbsp;B&lt;CODE&gt;&lt;/CODE&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, you are not selecting the &lt;STRONG&gt;MAT&lt;/STRONG&gt; column in the in-line view above, but only the distinct &lt;STRONG&gt;Division_ID&lt;/STRONG&gt; is being returned. There is no &lt;STRONG&gt;B.MAT&lt;/STRONG&gt; column to select.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without seeing the data it's hard to give you a solution for your specific problem. But you might want to include the columns you are selecting in the main SELECT clause in your in-line views. Here is a new in-line view B that should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(Select DISTINCT DIVISION_ID, MAT, ART, MAC FROM ODS.R_M)&amp;nbsp;B&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now this will give you the unique combinations of &lt;STRONG&gt;Division_ID, MAT, ART&lt;/STRONG&gt; and &lt;STRONG&gt;MAC&lt;/STRONG&gt;. Not sure if that is what you are looking for. It might be easier to create separate views for those in-line views in their own queries, make sure those views are what you need, then use those to join. Example data would help.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Peter&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 13:26:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Do-An-Inner-Join-On-Distinct-Observations/m-p/592660#M169951</guid>
      <dc:creator>Panagiotis</dc:creator>
      <dc:date>2019-09-30T13:26:32Z</dc:date>
    </item>
  </channel>
</rss>

