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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: