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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.