BookmarkSubscribeRSS Feed
GAL1986
Fluorite | Level 6

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;

2 REPLIES 2
sbxkoenk
SAS Super FREQ

Hello,

 

I haven't read your program (nor the paper it is based on), but the easiest technique is :

to delete the already matched controls from the data set "controls" in order to ensure that controls are used only once.

 

That technique is used in the program that is presented in this paper :

Matching Cases and Controls Using SAS® Software
Laura Quitzau Mortensen, Kristoffer Andresen, Jakob Burcharth, Hans-Christian Pommergaard, and Jacob Rosenberg

https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7931898/

 

Good luck,

Koen

GAL1986
Fluorite | Level 6
Thank you, I will take a look at that reference.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 2 replies
  • 573 views
  • 1 like
  • 2 in conversation