<?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: Joinng more than one table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543477#M150236</link>
    <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; Thank you for your quick reply. I made a mistake in the post, and I have corrected it now. table one has to be joined with country_one and country_two to get the "name" column.</description>
    <pubDate>Fri, 15 Mar 2019 10:54:58 GMT</pubDate>
    <dc:creator>Myurathan</dc:creator>
    <dc:date>2019-03-15T10:54:58Z</dc:date>
    <item>
      <title>Joinng more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543460#M150230</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following tables.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input countryid id value;
datalines;
1 001 5260
1 002 5698
1 003 3256
2 004 5698
2 005 6589
;
run;

data country_one;
input countryid id name;
datalines;
1 001 sam
1 002 jim
1 003 dim
;
run;

data country_two;
input countryid id name;
datalines;
2 004 bill
2 005 jill
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current code looks like this.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table a as 
select a.*, b.name
from one as a 
left join country_one as b
on a.countryid = b.countryid and a.id =b.id
where a.countryid =1;
quit;

proc sql;
create table b as 
select a.*,b.name
from one as a 
left join country_two as b
on a.countryid = b.countryid and a.id =b.id
where a.countryid =2;
quit;

data country_one;
set a b;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;There should be a better way to do it. Could you guys help me on this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 10:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543460#M150230</guid>
      <dc:creator>Myurathan</dc:creator>
      <dc:date>2019-03-15T10:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: Joinng more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543474#M150234</link>
      <description>&lt;P&gt;You can use union all as the tables are the same - which begs the question, one which we often ask here, which is why you have the same data in two different datasets which is never a good way of working.&amp;nbsp; Always (except in very specialized circumstances) keep data which is the same in one dataset as it makes processing faster, programming simpler etc.&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table want as 
  select *
  from   (select * from country_one union all select * from country_two)
  where  countrid in (1,2);
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Mar 2019 10:47:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543474#M150234</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-03-15T10:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: Joinng more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543477#M150236</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; Thank you for your quick reply. I made a mistake in the post, and I have corrected it now. table one has to be joined with country_one and country_two to get the "name" column.</description>
      <pubDate>Fri, 15 Mar 2019 10:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543477#M150236</guid>
      <dc:creator>Myurathan</dc:creator>
      <dc:date>2019-03-15T10:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Joinng more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543478#M150237</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are you trying to do ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the following step :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table a as 
select a.*
from one as a 
left join country_one as b
on a.countryid = b.countryid and a.id =b.id
where a.countryid =1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the join of table country_one is completely useless since you don't&lt;/P&gt;
&lt;P&gt;retrieve any column from this dataset nor use its columns to filter the results.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 10:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543478#M150237</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-03-15T10:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Joinng more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543479#M150238</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt; Yes, I have made a mistake. I have corrected it now in the post</description>
      <pubDate>Fri, 15 Mar 2019 10:57:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543479#M150238</guid>
      <dc:creator>Myurathan</dc:creator>
      <dc:date>2019-03-15T10:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: Joinng more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543480#M150239</link>
      <description>&lt;PRE&gt;proc sql;
  create table want as 
  select a.*,&lt;BR /&gt;         b.name
  from   one a&lt;BR /&gt;  left join (select * from country_one union all select * from country_two)&lt;BR /&gt;  on     a.countryid=b.countryid&lt;BR /&gt;  where  countrid in (1,2);
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Mar 2019 10:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543480#M150239</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-03-15T10:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Joinng more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543482#M150240</link>
      <description>&lt;P&gt;You can chain the joins and use coalesce function as follows :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
create table want as 
select a.*, coalescec(b.name, c.name) as name
from one as a 
left join country_one as b
on a.countryid = b.countryid and a.id =b.id
left join country_two as c
on a.countryid = c.countryid and a.id =c.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Mar 2019 11:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543482#M150240</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-03-15T11:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Joinng more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543489#M150241</link>
      <description>&lt;P&gt;seems more of a case where you could use a simple data merge to obtain your results, rather than all the left, right and unions needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 11:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543489#M150241</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-03-15T11:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Joinng more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543490#M150242</link>
      <description>&lt;P&gt;Pure data step method:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data countries;
set
  country_one
  country_two
;
by countryid id; /* guarantees correct interleaving */
run;

data want;
merge
  one
  countries
;
by countryid id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Mar 2019 11:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543490#M150242</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-15T11:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Joinng more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543494#M150244</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;, Thank you for your help. I have one question how can I use coalesces for numeric columns?</description>
      <pubDate>Fri, 15 Mar 2019 11:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543494#M150244</guid>
      <dc:creator>Myurathan</dc:creator>
      <dc:date>2019-03-15T11:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Joinng more than one table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543496#M150245</link>
      <description>&lt;P&gt;When browsing the documentation for the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p1g9btrql8d9x6n1iz6yowaqrq1v.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;COALESCEC&lt;/A&gt; function, you will notice that there is a page for the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p1vjttz6nuankzn1gh4z3wgcu0bf.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;COALESCE&lt;/A&gt; function right next to it. That's the one for numeric values.&lt;/P&gt;
&lt;P&gt;This is part of the usefulness of Maxim 1.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 11:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Joinng-more-than-one-table/m-p/543496#M150245</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-15T11:59:00Z</dc:date>
    </item>
  </channel>
</rss>

