DATA Step, Macro, Functions and more

matching case-control

Regular Contributor
Posts: 182

matching case-control

[ Edited ]


Hi!  I recently used some syntax you created for a match sase- control table for a question posted in 2012:


This seemed to work but I need some help troubleshooting.


1.  The control id (ne_ssn) is duplicating and being used more than once.  I want to be matched only once to a case (e_ssn).

2.  Some cases are matched to over 200+ controls.  I want to limit it to 5 matches.

3. I seems some of my cases are not appearing at all in my final table (e.g. 620K cases but final table only matched 600K cases).  Does this mean there are no matches at all for the missing?


Any help is much apprecited!!


Here is my syntax:

proc sort data=tmp;
by service_entry_date study rand_num;
* 'study' variable is 1=case 0=control;

proc rank data=tmp out=tempR;
by service_entry_date study;
var rand_num;
*assign random order;

proc sql;
create table exp2.match as
select a.ssn as e_ssn, a.service_branch as e_service_branch, as e_sex, a.service_entry_date as e_service_entry_date,,
b.ssn as ne_ssn, b.service_branch as ne_service_branch, as ne_sex, b.service_entry_date as ne_service_entry_date,
from tempr as a inner join tempr as b
     on( a.service_entry_date between b.service_entry_date and b.service_entry_date_low) and a.service_branch=b.service_branch and and a.rand_num=ceil(b.rand_num/5)
where and not;
drop table tmp, tmpR;

Esteemed Advisor
Posts: 5,526

Re: matching case-control

"This seemed to work" but it clearly doesn't. Therefore, your problem must be different from the one posted in 2012.


Please post this question as a new topic with your description of the case-control matching rules and some test data.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation