I have 2 tables that I need to join.
1. Patients
2. LabResults
I want everyone in the Patients table.
I only want LabResults that match records in the Patients table.
The identifier that both tables contain is PatientID
How do I match all records in the Patients table to those that have the same PatientID in the LabResults table?
This is called a MERGE.
data want;
merge patients lab_results;
by patientid;
run;
If you want to exclude lab results that are not actually from patients (how did they get into your database then?) you can use the IN= dataset option to create temporary indicator variables to indicate if the the given dataset is contributing to the current observation.
data want;
merge patients(in=in1) lab_results;
by patientid;
if not in1 then do;
if first.patientid then put 'ERROR: ' patientid= 'found in LABRESULTS but not in PATIENTS.';
delete;
end;
run;
This is called a MERGE.
data want;
merge patients lab_results;
by patientid;
run;
If you want to exclude lab results that are not actually from patients (how did they get into your database then?) you can use the IN= dataset option to create temporary indicator variables to indicate if the the given dataset is contributing to the current observation.
data want;
merge patients(in=in1) lab_results;
by patientid;
if not in1 then do;
if first.patientid then put 'ERROR: ' patientid= 'found in LABRESULTS but not in PATIENTS.';
delete;
end;
run;
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.
Ready to level-up your skills? Choose your own adventure.