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;

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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