BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Shradha1
Obsidian | Level 7

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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;

View solution in original post

1 REPLY 1
Shmuel
Garnet | Level 18

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 743 views
  • 0 likes
  • 2 in conversation