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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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