<?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 SQL Code to combine tables having many to many relation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-Code-to-combine-tables-having-many-to-many-relation/m-p/281256#M56996</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I am looking for a sql code to combine two tables: admission and insurance where a person having coverage in part by 2 insurance companies following each admission. I came across example in community that suggest use of multiple set statements. I am interested to know the possible solution using sql code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data admission;
input id $ date $ ;
datalines;
1 10102015
1 11103015
;
run;


data insurance;
input id $ company $;
datalines;
1 MOH
1 sunlife
;
run;

/*merge  not allow many to many relation*/
proc sort data =admission; by id ; run;
proc sort data =insurance; by id ; run;
data merged;
merge admission (in=a) insurance(in=b);
by id;
if a=b;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you in advance for your kind reply.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Deepak&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Jun 2016 20:13:59 GMT</pubDate>
    <dc:creator>DeepakSwain</dc:creator>
    <dc:date>2016-06-29T20:13:59Z</dc:date>
    <item>
      <title>SQL Code to combine tables having many to many relation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Code-to-combine-tables-having-many-to-many-relation/m-p/281256#M56996</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I am looking for a sql code to combine two tables: admission and insurance where a person having coverage in part by 2 insurance companies following each admission. I came across example in community that suggest use of multiple set statements. I am interested to know the possible solution using sql code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data admission;
input id $ date $ ;
datalines;
1 10102015
1 11103015
;
run;


data insurance;
input id $ company $;
datalines;
1 MOH
1 sunlife
;
run;

/*merge  not allow many to many relation*/
proc sort data =admission; by id ; run;
proc sort data =insurance; by id ; run;
data merged;
merge admission (in=a) insurance(in=b);
by id;
if a=b;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you in advance for your kind reply.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Deepak&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 20:13:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Code-to-combine-tables-having-many-to-many-relation/m-p/281256#M56996</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-06-29T20:13:59Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Code to combine tables having many to many relation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Code-to-combine-tables-having-many-to-many-relation/m-p/281258#M56997</link>
      <description>&lt;P&gt;What is the expected output?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 20:16:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Code-to-combine-tables-having-many-to-many-relation/m-p/281258#M56997</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-29T20:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Code to combine tables having many to many relation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Code-to-combine-tables-having-many-to-many-relation/m-p/281260#M56998</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected output is attached for your kind consideration.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Deepak&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 20:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Code-to-combine-tables-having-many-to-many-relation/m-p/281260#M56998</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-06-29T20:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Code to combine tables having many to many relation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Code-to-combine-tables-having-many-to-many-relation/m-p/281262#M56999</link>
      <description>&lt;P&gt;Please post as text rather than an attachment.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 20:31:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Code-to-combine-tables-having-many-to-many-relation/m-p/281262#M56999</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-29T20:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Code to combine tables having many to many relation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Code-to-combine-tables-having-many-to-many-relation/m-p/281364#M57049</link>
      <description>&lt;P&gt;Your SQL step might look like that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table merged as
select
  a.*,
  b.company
from admission a, insurance b
where a.id = b.id;
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The resulting table would look like this:&lt;/P&gt;
&lt;PRE&gt;Obs    id      date      company

 1     1     10102015    MOH    
 2     1     10102015    sunlife
 3     1     11103015    MOH    
 4     1     11103015    sunlife
&lt;/PRE&gt;
&lt;P&gt;Mind that I won't open a MS Office document from the web. Post data as a datastep or in text form.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 08:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Code-to-combine-tables-having-many-to-many-relation/m-p/281364#M57049</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-30T08:00:08Z</dc:date>
    </item>
  </channel>
</rss>

