<?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 Understanding joins in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/586943#M167569</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to get a certain output through a join.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code for creating Input datasets:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rank;
infile datalines; 
input rmg $4. acc;
datalines; 
123	1
124	2
125	3
126	4
127	5
; 
run;

data rank1;
infile datalines; 
input rmg $4. acc;
datalines; 
123	1
124	2
125	3
123	7
124	8
125	9
136	10
138	11
; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I'm looking to do is get all the data from table rank and get only that data from table rank1 where rank.rmg=rank1.rmg but rank.acc is not in rank1.acc to avoid duplication. So for eg, for rmg 123 in rank, the code should include 123 from rank, but in addition should also pull 123&amp;nbsp; from rank1 where acc is not 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this is the output that I'm looking to get:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;rmg&lt;/TD&gt;&lt;TD&gt;acc&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;126&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;127&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try this code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table new as
select rank.*, rank1.rmg, rank1.acc from rank left join rank1
on rank.rmg=rank1.rmg
where rank1.acc not in (select distinct acc from rank);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get this output:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;rmg&lt;/TD&gt;&lt;TD&gt;acc&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;126&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;127&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then when I try this code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table new as
select rank.*, rank1.rmg as rmg1, rank1.acc as acc1 from rank left join rank1
on rank.rmg=rank1.rmg
where rank1.acc not in (select distinct acc from rank);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get this output:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;rmg&lt;/TD&gt;&lt;TD&gt;acc&lt;/TD&gt;&lt;TD&gt;rmg1&lt;/TD&gt;&lt;TD&gt;acc1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;126&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;127&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What should I be changing to get the desired output? Appreciate any suggestions.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Sat, 07 Sep 2019 05:58:01 GMT</pubDate>
    <dc:creator>AJ_Brien</dc:creator>
    <dc:date>2019-09-07T05:58:01Z</dc:date>
    <item>
      <title>Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/586943#M167569</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to get a certain output through a join.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code for creating Input datasets:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rank;
infile datalines; 
input rmg $4. acc;
datalines; 
123	1
124	2
125	3
126	4
127	5
; 
run;

data rank1;
infile datalines; 
input rmg $4. acc;
datalines; 
123	1
124	2
125	3
123	7
124	8
125	9
136	10
138	11
; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I'm looking to do is get all the data from table rank and get only that data from table rank1 where rank.rmg=rank1.rmg but rank.acc is not in rank1.acc to avoid duplication. So for eg, for rmg 123 in rank, the code should include 123 from rank, but in addition should also pull 123&amp;nbsp; from rank1 where acc is not 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this is the output that I'm looking to get:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;rmg&lt;/TD&gt;&lt;TD&gt;acc&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;126&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;127&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try this code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table new as
select rank.*, rank1.rmg, rank1.acc from rank left join rank1
on rank.rmg=rank1.rmg
where rank1.acc not in (select distinct acc from rank);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get this output:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;rmg&lt;/TD&gt;&lt;TD&gt;acc&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;126&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;127&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then when I try this code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table new as
select rank.*, rank1.rmg as rmg1, rank1.acc as acc1 from rank left join rank1
on rank.rmg=rank1.rmg
where rank1.acc not in (select distinct acc from rank);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get this output:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;rmg&lt;/TD&gt;&lt;TD&gt;acc&lt;/TD&gt;&lt;TD&gt;rmg1&lt;/TD&gt;&lt;TD&gt;acc1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;126&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;127&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What should I be changing to get the desired output? Appreciate any suggestions.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 07 Sep 2019 05:58:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/586943#M167569</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-09-07T05:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/586953#M167571</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265086"&gt;@AJ_Brien&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Methinks that judging from your input/output data logic, what you're looking for is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rank ;                                                                                                                                                                                                                                                     
  input rmg :$3. acc ;                                                                                                                                                                                                                                          
  cards ;                                                                                                                                                                                                                                                       
123  1                                                                                                                                                                                                                                                          
124  2                                                                                                                                                                                                                                                          
125  3                                                                                                                                                                                                                                                          
126  4                                                                                                                                                                                                                                                          
127  5                                                                                                                                                                                                                                                          
;                                                                                                                                                                                                                                                               
run ;                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                
data rank1;                                                                                                                                                                                                                                                     
  input rmg :$3. acc ;                                                                                                                                                                                                                                          
  cards ;                                                                                                                                                                                                                                                       
123   1                                                                                                                                                                                                                                                         
124   2                                                                                                                                                                                                                                                         
125   3                                                                                                                                                                                                                                                         
123   7                                                                                                                                                                                                                                                         
124   8                                                                                                                                                                                                                                                         
125   9                                                                                                                                                                                                                                                         
136  10                                                                                                                                                                                                                                                         
138  11                                                                                                                                                                                                                                                         
;                                                                                                                                                                                                                                                               
run ;                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                
proc sql ;                                                                                                                                                                                                                                                      
  create table want as                                                                                                                                                                                                                                          
  select * from rank                                                                                                                                                                                                                                            
  union                                                                                                                                                                                                                                                         
  select * from rank1 where rmg in (select rmg from rank)                                                                                                                                                                                                       
  ;                                                                                                                                                                                                                                                             
quit ;                                                        
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;UNION (without ALL) unduplicates the rows with the same RMG and ACC.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Sep 2019 08:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/586953#M167571</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-07T08:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587005#M167582</link>
      <description>Thank you for your reply.&lt;BR /&gt;&lt;BR /&gt;The only drawback I see with this approach is that is the moment I add additional columns in the 1st dataset (which I probably do need to do), it gives the error: Corresponding select-list expressions are not compatible, that's the reason I was trying to go with left join.</description>
      <pubDate>Sat, 07 Sep 2019 22:47:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587005#M167582</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-09-07T22:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587009#M167583</link>
      <description>&lt;P&gt;Try OUTER UNION CORRESPONDING instead of UNION in &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt; 's example then.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Sep 2019 23:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587009#M167583</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-09-07T23:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587021#M167590</link>
      <description>&lt;P&gt;thank you for your reply, but outer union corresponding would create additional columns for me.&lt;BR /&gt;&lt;BR /&gt;So to recap, I made slight changes to my input dataset to accomodate more columns, and change their names too:&lt;BR /&gt;&lt;BR /&gt;data rank;/*base*/&lt;BR /&gt;infile datalines;&lt;BR /&gt;input check $2. rmgid $4. accno blah $2.;&lt;BR /&gt;datalines;&lt;BR /&gt;y 123 1 y&lt;BR /&gt;n 124 2 n&lt;BR /&gt;y 125 3 y&lt;BR /&gt;n 126 4 n&lt;BR /&gt;y 127 5 y&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data rank1;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input rmg $4. acc;&lt;BR /&gt;datalines;&lt;BR /&gt;123 1&lt;BR /&gt;124 2&lt;BR /&gt;125 3&lt;BR /&gt;123 7&lt;BR /&gt;124 8&lt;BR /&gt;125 9&lt;BR /&gt;136 10&lt;BR /&gt;138 11&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;and the output I'm trying for is:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;check&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;rmgid&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;accno&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;blah&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Y&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;123&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Y&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;N&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;124&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;N&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Y&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;125&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Y&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;N&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;126&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;4&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;N&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Y&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;127&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;5&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Y&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;123&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;7&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;124&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;8&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;125&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;9&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Basically trying to union them such that I get all the data from table rank and get only that data from table rank1 where rank.rmgid=rank1.rmg but rank.accno is not in rank1.acc to avoid duplication.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2019 00:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587021#M167590</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-09-08T00:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587023#M167591</link>
      <description>&lt;P&gt;Does SELECT DISTINCT instead of just SELECT give you the result you want?&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2019 01:04:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587023#M167591</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-09-08T01:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587025#M167593</link>
      <description>I can't use distinct in the select statements because the rmgs are associated with different acc and I need to include them all.&lt;BR /&gt;The issue here is that I need the result to look kind of like it does for union (rows added below, no additional columns created), but the concern is that the 1st table contains differennt columns than the 2nd one, so simple union isn't working.</description>
      <pubDate>Sun, 08 Sep 2019 01:12:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587025#M167593</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-09-08T01:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587028#M167595</link>
      <description>I tried another way: this might get me closer to where I want to be, sadly one of the queries for creating table temp1 gives me a blank output for some reason!?! Appreciate any help I can get with this, I've tried a number of ways with this query, but no result so far! This seemed easy initially, but feels tricky now&lt;BR /&gt;&lt;BR /&gt;proc sql ;&lt;BR /&gt;create table temp as&lt;BR /&gt;select rmgid, accno from rank;&lt;BR /&gt;&lt;BR /&gt;create table temp1 as /*this gives me a blank output, not sure why*/&lt;BR /&gt;select rmg as rmgid,acc as accno from rank1&lt;BR /&gt;where rmg in (select rmgid from rank)&lt;BR /&gt;and acc not in (select distinct accno from rank);&lt;BR /&gt;&lt;BR /&gt;insert into temp&lt;BR /&gt;select rmgid, accno from temp1;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select *, temp.rmgid,temp.accno&lt;BR /&gt;from rank full join temp&lt;BR /&gt;on rank.accno=temp.accno;&lt;BR /&gt;quit;</description>
      <pubDate>Sun, 08 Sep 2019 01:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587028#M167595</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-09-08T01:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587031#M167597</link>
      <description>&lt;P&gt;Cheating.....&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;                                                                                                                                                                                                                                                      
  create table want as                                                                                                                                                                                                                                          
  select * from rank
  union  
  select  ' ' as check
         ,rmgid
         ,accno
         ,' ' as blah
  from rank1
  where rmgid in (select rmgid from rank) 
  and accno not in (select accno from rank) 
  order by accno 
  ;                                                                                                                                                                                                                                                             
quit ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Sep 2019 02:34:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587031#M167597</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-09-08T02:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587034#M167599</link>
      <description>Strangely, that's giving me this result:&lt;BR /&gt;check rmgid accno blah&lt;BR /&gt;Y 123 1 Y&lt;BR /&gt;N 124 2 N&lt;BR /&gt;Y 125 3 Y&lt;BR /&gt;N 126 4 N&lt;BR /&gt;Y 127 5 Y&lt;BR /&gt;&lt;BR /&gt;Feels like the where conditions are not working for some reason.&lt;BR /&gt;But I have another question, and you'll hate me for saying this, but is this scalable? Meaning in this scenario I luckily happen to have just 4 columns in rank, but what if I have 100 columns or so. Trying to understand the best way to perform this logic and become better. Thank you for your help so far!</description>
      <pubDate>Sun, 08 Sep 2019 03:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587034#M167599</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-09-08T03:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587036#M167600</link>
      <description>&lt;P&gt;Works fine for me with this complete program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rank;
infile datalines;
input check $2. rmgid $4. accno blah $2.;
datalines;
y 123 1 y
n 124 2 n
y 125 3 y
n 126 4 n
y 127 5 y
;
run;                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                
data rank1;
infile datalines;
input rmgid $4. accno;
datalines;
123 1
124 2
125 3
123 7
124 8
125 9
136 10
138 11
;
run;

proc sql ;                                                                                                                                                                                                                                                      
  create table want as                                                                                                                                                                                                                                          
  select * from rank
  union  
  select  ' ' as check
         ,rmgid
         ,accno
         ,' ' as blah
  from rank1
  where rmgid in (select rmgid from rank) 
  and accno not in (select accno from rank) 
  order by accno 
  ;                                                                                                                                                                                                                                                             
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to scale this solution then I'd probably start looking at using DATA steps as they are a whole lot more flexible for stacking tables.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2019 03:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587036#M167600</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-09-08T03:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587037#M167601</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&amp;gt;&lt;SPAN&gt;If you want to scale this solution then I'd probably start looking at using DATA steps as they are a whole lot more flexible for stacking tables.&amp;lt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You snatched it off the tip of my proverbial online tongue ;).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And thank you for joining (no pun intended) the thread with your astute responses.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Kind regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Paul D.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2019 03:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587037#M167601</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-08T03:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587039#M167603</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp; - Thanks for providing the original UNION solution - I just started playing with it...&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2019 03:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587039#M167603</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-09-08T03:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587094#M167633</link>
      <description>thank you so much for all your help &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;! I get to learn so much from this community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Sun, 08 Sep 2019 18:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-joins/m-p/587094#M167633</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-09-08T18:19:32Z</dc:date>
    </item>
  </channel>
</rss>

