Hi everyone.
I have two large data sets.
Data1 is my main data set with missing information. I need to get that information in Data2 to fill the gap in Data1.
Data1
Name Admission_date Smoking_Status Weight
Maria 22Nov16 1 120
Maria 10Dec20 2
Luna 02Jan15 85
Rey 18Mar19 2 100
Rey 05May21 3 105
Jim 13Sep14
Data2
Name Admission_date Smoking_Status Weight
Maria 10Dec20 2 110
Luna 02Jan15 3 85
Rey 18Mar19 2 100
Juan 12Aug21 1 75
Jim 13Sep14 1 na
So my final data set would like the one below.
Final data
Name Admission_date Smoking_Status Weight
Maria 22Nov16 1 120
Maria 10Dec20 2 110
Luna 02Jan15 3 85
Rey 18Mar19 2 100
Rey 05May21 3 105
Jim 13Sep14 1 na
Thank you very much in advance for your help!
Assuming data is sorted by Name and ID and you can merge by those.
data want;
merge data1 (rename = (smoking_status = smoke1 weight = weight1))
data2 (rename = (smoking_status = smoke2 weight = weight2));
by name admission_date;
smoking_status = coalesce(smoke1, smoke2);
weight = coalesce(weight1, weight2);
run;
@yoyong555 wrote:
Hi everyone.
I have two large data sets.
Data1 is my main data set with missing information. I need to get that information in Data2 to fill the gap in Data1.
Data1
Name Admission_date Smoking_Status Weight
Maria 22Nov16 1 120
Maria 10Dec20 2
Luna 02Jan15 85
Rey 18Mar19 2 100
Rey 05May21 3 105
Jim 13Sep14
Data2
Name Admission_date Smoking_Status Weight
Maria 10Dec20 2 110
Luna 02Jan15 3 85
Rey 18Mar19 2 100
Juan 12Aug21 1 75
Jim 13Sep14 1 na
So my final data set would like the one below.
Final data
Name Admission_date Smoking_Status Weight
Maria 22Nov16 1 120
Maria 10Dec20 2 110
Luna 02Jan15 3 85
Rey 18Mar19 2 100
Rey 05May21 3 105
Jim 13Sep14 1 na
Thank you very much in advance for your help!
Assuming data is sorted by Name and ID and you can merge by those.
data want;
merge data1 (rename = (smoking_status = smoke1 weight = weight1))
data2 (rename = (smoking_status = smoke2 weight = weight2));
by name admission_date;
smoking_status = coalesce(smoke1, smoke2);
weight = coalesce(weight1, weight2);
run;
@yoyong555 wrote:
Hi everyone.
I have two large data sets.
Data1 is my main data set with missing information. I need to get that information in Data2 to fill the gap in Data1.
Data1
Name Admission_date Smoking_Status Weight
Maria 22Nov16 1 120
Maria 10Dec20 2
Luna 02Jan15 85
Rey 18Mar19 2 100
Rey 05May21 3 105
Jim 13Sep14
Data2
Name Admission_date Smoking_Status Weight
Maria 10Dec20 2 110
Luna 02Jan15 3 85
Rey 18Mar19 2 100
Juan 12Aug21 1 75
Jim 13Sep14 1 na
So my final data set would like the one below.
Final data
Name Admission_date Smoking_Status Weight
Maria 22Nov16 1 120
Maria 10Dec20 2 110
Luna 02Jan15 3 85
Rey 18Mar19 2 100
Rey 05May21 3 105
Jim 13Sep14 1 na
Thank you very much in advance for your help!
data want;
update data1
data2;
by name admission_date;
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: