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;
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!
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.