DATA Step, Macro, Functions and more

Merging Problem

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Merging Problem

Hi,

 

I have two datasets:

 

Dataset A:

ID  Gender

1     M

 

Dataset B:

Date

1/1/2010

1/2/2010

 

I'm trying to create a dataset that looks like this:

ID  Gender  Date

1     M          1/1/2010

1     M          1/2/2010

 

Is that possible?


Accepted Solutions
Solution
‎05-23-2018 10:48 AM
Occasional Contributor
Posts: 5

Re: Merging Problem

Posted in reply to novinosrin

Thank you so much!  

View solution in original post


All Replies
PROC Star
Posts: 1,846

Re: Merging Problem

[ Edited ]
Posted in reply to KatLinden

 

data a;
input ID  Gender $;
cards;
1     M
;
data b;
input Date $10.;
cards;
1/1/2010
1/2/2010
;
data want;
if 0 then set a;
set b;
if _n_=1 then set a;
run;

 

Solution
‎05-23-2018 10:48 AM
Occasional Contributor
Posts: 5

Re: Merging Problem

Posted in reply to novinosrin

Thank you so much!  

PROC Star
Posts: 1,846

Re: Merging Problem

Posted in reply to KatLinden

@KatLinden Welcome to the SAS community forum. I hope you have a fun journey with us Smiley Happy

Occasional Contributor
Posts: 5

Re: Merging Problem

Posted in reply to novinosrin

Thank you!  One more question.  How does this work if I have several observations in dataset A?

 

I have two datasets:

 

Dataset A:

ID  Gender

1     M

2     F

.

.

.

etc

 

Dataset B:

Date

1/1/2010

1/2/2010

 

I'm trying to create a dataset that looks like this:

ID  Gender  Date

1     M          1/1/2010

1     M          1/2/2010

2     F           1/1/2010

2     F           1/2/2010

.

.

.

etc

 

PROC Star
Posts: 1,846

Re: Merging Problem

Posted in reply to KatLinden

I would request you to provide us a more comprehensive and complete representative sample. Your data doesn't seem to have clear logic of match apart from mere plugging in 1 and 2 dates to gender category. Or is that all the data is?

Occasional Contributor
Posts: 5

Re: Merging Problem

Posted in reply to novinosrin

Yes, but I have hundreds of observations in dataset A, each observation has a unique ID and I need to insert 2 dates.

PROC Star
Posts: 1,846

Re: Merging Problem

[ Edited ]
Posted in reply to KatLinden
data a;
input ID  Gender $;
cards;
1     M
2     F
;
data b;
input Date $10.;
cards;
1/1/2010
1/2/2010
;
proc sql;
create table want as
select *
from a,b
order by id,gender;
quit;
PROC Star
Posts: 1,846

Re: Merging Problem

Posted in reply to novinosrin

still i am only playing with your data without making much sense lol 

Occasional Contributor
Posts: 5

Re: Merging Problem

Posted in reply to novinosrin

That worked perfectly!  Thank you so much!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 141 views
  • 0 likes
  • 2 in conversation