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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.