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
Assuming both data are sorted by ID the most efficient way will be by:
data want;
merge data1 data2;
by id;
run;
Already sorted by ID date?if yes
data want;
merge one two
by id;
run;
if not, then sort and use the above code
Assuming both data are sorted by ID the most efficient way will be by:
data want;
merge data1 data2;
by id;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.