I have two datasets data1 and data2 with information on students' weight before 1 month and after 1 month respectively. the Number of observations and names of students in both the datasets are not entirely same. How to I join them both to keep all the records in one place.
Data1:
student Weight_before
A 23
B 54
D 23
F 11
G 34
H 27
Data2:
student Weight_after
A 29
B 43
K 54
M 23
G 65
J 18
W 41
I want the final dataset to look like this:
student | Weight_before | Weight_after |
A | 23 | 29 |
B | 54 | 43 |
D | 23 | . |
F | 11 | . |
G | 34 | 65 |
H | 27 | . |
K | . | 54 |
M | . | 23 |
J | . | 18 |
W | . | 41 |
How do I achieve this?
Thank you!
Use next code:
proc sort data=data1; by student; run;
proc sort data=data2; by student; run;
data want;
merge data1 data2;
by student;
run;
Use next code:
proc sort data=data1; by student; run;
proc sort data=data2; by student; run;
data want;
merge data1 data2;
by student;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.