<?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: Output the result of a join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Output-the-result-of-a-join/m-p/878878#M347242</link>
    <description>&lt;P&gt;If I understand your requirements correctly and assume that your 4 right tables have the same columns then something like this should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want1 as

  select '1' as JoinNum
        ,*
  from Table1 as T1
  inner join table2 as T2
  on T1.key = T2.key

  union

  select '2' as JoinNum
        ,*
  from Table1 as T1
  inner join table3 as T2
  on T1.key = T2.key

  union

  select '3' as JoinNum
        ,*
  from Table1 as T1
  inner join table4 as T2
  on T1.key = T2.key

  union

  select '4' as JoinNum
        ,*
  from Table1 as T1
  inner join table5 as T2
  on T1.key = T2.key

  order by key, JoinNum
  ;
quit;

data want2;
  set want1;
  by key JoinNum;
  if first.key;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The strategy is to do all 4 joins and to give each a priority. By sorting the 4 joins in priority order, you can ensure only the highest priority join is chosen.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Jun 2023 01:26:20 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2023-06-02T01:26:20Z</dc:date>
    <item>
      <title>Output the result of a join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-the-result-of-a-join/m-p/878846#M347220</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am doing an inner join.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have one left table and 4 right tables,&lt;/P&gt;
&lt;P&gt;I need to do inner joins with these 4 tables.&lt;/P&gt;
&lt;P&gt;left table with first right table then output&lt;/P&gt;
&lt;P&gt;left table with second right table then output&lt;/P&gt;
&lt;P&gt;until the end,&lt;/P&gt;
&lt;P&gt;but each time I do the joins, the second join should be with the rest of observations that&lt;/P&gt;
&lt;P&gt;were not joined in the first attempt.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this makes sense, if not, please let me know.&lt;/P&gt;
&lt;P&gt;Respectfully,&lt;/P&gt;
&lt;P&gt;blue&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 22:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-the-result-of-a-join/m-p/878846#M347220</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2023-06-01T22:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Output the result of a join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-the-result-of-a-join/m-p/878878#M347242</link>
      <description>&lt;P&gt;If I understand your requirements correctly and assume that your 4 right tables have the same columns then something like this should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want1 as

  select '1' as JoinNum
        ,*
  from Table1 as T1
  inner join table2 as T2
  on T1.key = T2.key

  union

  select '2' as JoinNum
        ,*
  from Table1 as T1
  inner join table3 as T2
  on T1.key = T2.key

  union

  select '3' as JoinNum
        ,*
  from Table1 as T1
  inner join table4 as T2
  on T1.key = T2.key

  union

  select '4' as JoinNum
        ,*
  from Table1 as T1
  inner join table5 as T2
  on T1.key = T2.key

  order by key, JoinNum
  ;
quit;

data want2;
  set want1;
  by key JoinNum;
  if first.key;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The strategy is to do all 4 joins and to give each a priority. By sorting the 4 joins in priority order, you can ensure only the highest priority join is chosen.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2023 01:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-the-result-of-a-join/m-p/878878#M347242</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-06-02T01:26:20Z</dc:date>
    </item>
  </channel>
</rss>

