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

Hi,

 

How can I do a one to many merge? I have included some sample data.

 

Data Set 1 

ID     Code

1       10

2       10

3       15

4       15

5       30

 

Data Set 2

ID   Date       

1     1/2/2019

1     1/3/2019

1     1/4/2019

3     1/2/2019

3     1/3/2019

3     1/4/2019

2     1/2/2019

2     1/3/2019

2     1/4/2019

4    1/2/2019

4    1/3/2019

4    1/4/2019

5    1/2/2019

5    1/3/2019

5    1/4/2019

 

Data Set I want:

ID   Date          Code

1     1/2/2019   10

1     1/3/2019   10

1     1/4/2019   10

3     1/2/2019   15

3     1/3/2019   15

3     1/4/2019   15

2     1/2/2019   10

2     1/3/2019   10

2     1/4/2019   10

4    1/2/2019    15

4    1/3/2019    15

4    1/4/2019    15

5    1/2/2019    30

5    1/3/2019    30

5    1/4/2019    30

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Assuming both data are sorted by ID the most efficient way will be by:

data want;
merge data1 data2;
  by id;
run;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Already sorted by ID date?if yes

 

data want;

merge one two

by id;

run;

 

if not, then sort and use the above code

Shmuel
Garnet | Level 18

Assuming both data are sorted by ID the most efficient way will be by:

data want;
merge data1 data2;
  by id;
run;
NickA1
Calcite | Level 5
proc sort data=Info2; by cusip; run;
proc sort data=Yieldsrenamed; by cusip; run;
data Merged;
merge Info2 Yieldsrenamed;
by cusip;
run;
Reeza
Super User
Please mark the question solved be selecting the appropriate answer.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 2996 views
  • 2 likes
  • 4 in conversation