Hi all, I am trying to do 1:1 matching while only using controls subjects once. I found the following code in a published paper ( https://support.sas.com/resources/papers/proceedings/proceedings/sugi29/173-29.pdf ) and I have adapted it for my project. I am able to identify matching based on my matching criteria BUT, the code allows controls to be used more than once. Can someone show me how to adapt this code for 1:1 matching without duplicating controls? PROC SQL; CREATE table possmatch as select one.del_id as case_id, two.del_id as control_id, one.case_preg_num as study_parity, two.parity_control as control_parity, one.case_age as study_age, two.control_age as control_age, one.gender as study_gender, two.gender_control as control_gender, one.insurance as study_insurance, two.insurance_control as control_insurance, one.case_year as study_year, two.control_year as year_control, one.rand_num as rand_num from cases one, controls two where ((one.case_year between two.year_low and two.year_high)and one.gender=two.gender_control and one.insurance=two.insurance_control and one.case_age=two.control_age and one.case_preg_num=two.parity_control); run; * count the number of control subjects for each case subject; proc sort data=possmatch; by case_id; run; data possmatch2(keep=case_id num_controls); set possmatch; by case_id; retain num_controls; if first.case_id then num_controls=1; else num_controls=num_controls+1; if last.case_id then output; run; * now merge the counts back into the dataset; data possmatch3; merge possmatch possmatch2; by case_id; run; * now order the rows to select the first matching control; proc sort data=possmatch3; by control_id num_controls rand_num; run; proc sort data=possmatch3 nodup; by control_id case_id; run; data possmatch4; set possmatch3; by control_id case_id; if first.control_id then output; run; /*Now, as before, randomly select the fixed number of control subjects for each case.*/ proc sort data=possmatch ; by case_id rand_num; run; data possmatch2 not_enough; set possmatch; by case_id ; retain num; if first.case_id then num=1; if num le 2 then do; output possmatch2; num=num+1; end; if last.case_id then do; if num le 2 then output not_enough; end;
... View more