<?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 PROC SQL JOIN Question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-JOIN-Question/m-p/597399#M172126</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate if you can advise on the behavior of the proc sql join&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I omit the bolded in the select statement i get the exact no of obs as in the A dataset i.e. 81 rows&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I include the bolded then there are more than 81 obs returned .. I believe there are some multile matches occuring&amp;nbsp;&lt;/P&gt;&lt;P&gt;but need help in understanding what is happening and how to include some variables from the other datasets such as N , D and at the same time have only 81 obs which is the no of rows in my A datset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE ONEDAY AS&lt;BR /&gt;SELECT DISTINCT&lt;BR /&gt;A.*,&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;N.INST_NO AS TRANS_INST_NACRS,&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;CASE WHEN MISSING(D.CIHI_KEY)=0 THEN 'DAD'&lt;BR /&gt;WHEN MISSING(N.CIHI_KEY)=0 THEN 'NACRS'&lt;BR /&gt;ELSE ''&lt;BR /&gt;END AS TRANS_TYPE,&lt;BR /&gt;MISSING(D.CIHI_KEY)=0 AS DAD_TRANSFER,&lt;BR /&gt;MISSING(N.CIHI_KEY)=0 AS NACRS_TRANSFER,&lt;BR /&gt;MISSING(D.CIHI_KEY)=0 OR MISSING(N.CIHI_KEY)=0 AS ANY_TRANSFER&lt;BR /&gt;FROM FinalDADAbstracts AS A&lt;BR /&gt;LEFT JOIN CIHI.DAD1819Q4 AS D&lt;BR /&gt;ON A.HCNE=D.HCNE AND A.HCNE~='9999999999'&lt;BR /&gt;AND (DATEPART(D.DISCH_DT)&amp;lt;=DATEPART(A.ADM_DT)&amp;lt;=DATEPART(D.DISCH_DT)+1)&lt;BR /&gt;LEFT JOIN CIHI.NACRS1819Q4 AS N&lt;BR /&gt;ON A.HCNE=N.HCNE AND A.HCNE~='9999999999'&lt;BR /&gt;AND A.CIHI_KEY~=N.CIHI_KEY&lt;BR /&gt;AND (DATEPART(N.Reg_DT)&amp;lt;=DATEPART(A.ADM_DT)&amp;lt;=DATEPART(N.Reg_DT)+1)&lt;BR /&gt;LEFT JOIN INST_EVT AS E&lt;BR /&gt;ON (D.INST_NO=STRIP(PUT(E.INST_AT,BEST32.)) OR N.INST_NO=STRIP(PUT(E.INST_AM,BEST32.)))&lt;BR /&gt;HAVING ANY_TRANSFER=1&lt;BR /&gt;ORDER BY A.CIHI_KEY;&lt;BR /&gt;QUIT;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Oct 2019 15:52:02 GMT</pubDate>
    <dc:creator>Ranjeeta</dc:creator>
    <dc:date>2019-10-17T15:52:02Z</dc:date>
    <item>
      <title>PROC SQL JOIN Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-JOIN-Question/m-p/597399#M172126</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate if you can advise on the behavior of the proc sql join&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I omit the bolded in the select statement i get the exact no of obs as in the A dataset i.e. 81 rows&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I include the bolded then there are more than 81 obs returned .. I believe there are some multile matches occuring&amp;nbsp;&lt;/P&gt;&lt;P&gt;but need help in understanding what is happening and how to include some variables from the other datasets such as N , D and at the same time have only 81 obs which is the no of rows in my A datset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE ONEDAY AS&lt;BR /&gt;SELECT DISTINCT&lt;BR /&gt;A.*,&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;N.INST_NO AS TRANS_INST_NACRS,&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;CASE WHEN MISSING(D.CIHI_KEY)=0 THEN 'DAD'&lt;BR /&gt;WHEN MISSING(N.CIHI_KEY)=0 THEN 'NACRS'&lt;BR /&gt;ELSE ''&lt;BR /&gt;END AS TRANS_TYPE,&lt;BR /&gt;MISSING(D.CIHI_KEY)=0 AS DAD_TRANSFER,&lt;BR /&gt;MISSING(N.CIHI_KEY)=0 AS NACRS_TRANSFER,&lt;BR /&gt;MISSING(D.CIHI_KEY)=0 OR MISSING(N.CIHI_KEY)=0 AS ANY_TRANSFER&lt;BR /&gt;FROM FinalDADAbstracts AS A&lt;BR /&gt;LEFT JOIN CIHI.DAD1819Q4 AS D&lt;BR /&gt;ON A.HCNE=D.HCNE AND A.HCNE~='9999999999'&lt;BR /&gt;AND (DATEPART(D.DISCH_DT)&amp;lt;=DATEPART(A.ADM_DT)&amp;lt;=DATEPART(D.DISCH_DT)+1)&lt;BR /&gt;LEFT JOIN CIHI.NACRS1819Q4 AS N&lt;BR /&gt;ON A.HCNE=N.HCNE AND A.HCNE~='9999999999'&lt;BR /&gt;AND A.CIHI_KEY~=N.CIHI_KEY&lt;BR /&gt;AND (DATEPART(N.Reg_DT)&amp;lt;=DATEPART(A.ADM_DT)&amp;lt;=DATEPART(N.Reg_DT)+1)&lt;BR /&gt;LEFT JOIN INST_EVT AS E&lt;BR /&gt;ON (D.INST_NO=STRIP(PUT(E.INST_AT,BEST32.)) OR N.INST_NO=STRIP(PUT(E.INST_AM,BEST32.)))&lt;BR /&gt;HAVING ANY_TRANSFER=1&lt;BR /&gt;ORDER BY A.CIHI_KEY;&lt;BR /&gt;QUIT;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 15:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-JOIN-Question/m-p/597399#M172126</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2019-10-17T15:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL JOIN Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-JOIN-Question/m-p/597416#M172137</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have multiple values of N.inst_no for matching criteria when the join occurs that is what happens.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data work.one;
   x='A';
run;

data work.two;
   input x $1. y;
datalines;
A 1
A 2
;

proc sql;
   create table work.out as
   select distinct a.*, b.y
   from work.one as a
        left join
        work.two as b
        on a.x = b.x
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;If you only want one value for the N.Inst_no then you need to filter the N aliased set prior to the join in some fashion.&lt;/P&gt;
&lt;P&gt;Distinct considers ALL the variables' levels, not just from one set. So multiple values of N.inst_no are distinct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post code in a code box for readability (or do you not use any indenting of your code at all?). When coding in all caps without any indents code is very hard to read.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 16:17:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-JOIN-Question/m-p/597416#M172137</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-17T16:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL JOIN Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-JOIN-Question/m-p/597452#M172148</link>
      <description>&lt;P&gt;Thankyou for pointing me in the direction of the issue&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will paste it in a box for future&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 17:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-JOIN-Question/m-p/597452#M172148</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2019-10-17T17:31:20Z</dc:date>
    </item>
  </channel>
</rss>

