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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.