BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DeepakSwain
Pyrite | Level 9

Hi there,

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.

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;

Thank you in advance for your kind reply.

Regards,

Deepak 

Swain
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Your SQL step might look like that:

proc sql;
create table merged as
select
  a.*,
  b.company
from admission a, insurance b
where a.id = b.id;
;
quit;

The resulting table would look like this:

Obs    id      date      company

 1     1     10102015    MOH    
 2     1     10102015    sunlife
 3     1     11103015    MOH    
 4     1     11103015    sunlife

Mind that I won't open a MS Office document from the web. Post data as a datastep or in text form.

View solution in original post

4 REPLIES 4
Reeza
Super User

What is the expected output?

DeepakSwain
Pyrite | Level 9

Hi Reeza,

 

Expected output is attached for your kind consideration. 

 

Regards,

Deepak

Swain
Reeza
Super User

Please post as text rather than an attachment. 

Kurt_Bremser
Super User

Your SQL step might look like that:

proc sql;
create table merged as
select
  a.*,
  b.company
from admission a, insurance b
where a.id = b.id;
;
quit;

The resulting table would look like this:

Obs    id      date      company

 1     1     10102015    MOH    
 2     1     10102015    sunlife
 3     1     11103015    MOH    
 4     1     11103015    sunlife

Mind that I won't open a MS Office document from the web. Post data as a datastep or in text form.

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2130 views
  • 2 likes
  • 3 in conversation