Date: Mon, 9 Dec 2002 17:24:00 -0500
Reply-To: Howard_Schreier@ITA.DOC.GOV
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Howard_Schreier@ITA.DOC.GOV
Subject: Re: sas question
Do you also want overall optimization (minimizing the aggregate absolute
difference)? That profoundly changes the nature of the problem; you need
operations research tools.
People have recommended the Mayo clinic macro
http://www.mayo.edu/hsr/sasmac/match.sas
It supports both optimal and so-called "greedy" methods. I believe you need
SAS/OR for the former.
On Mon, 9 Dec 2002 12:36:05 -0500, Derek Fugh <Derek.Fugh@MEDSTAT.COM>
wrote:
>Hi group,
>
>I am trying to match a treatment group to control by propensity score. The
>following SAS code will match treatment to control but the problem is that
>multiple treatment group folks can be matched to a single control (control
>ID 2008 is used twice). I need to modify the code so that it will give me
>unique 1-to-1 match. Please help.
>
>Thanks,
>Derek
>
>
>
>***************************************************************************
*
> /* DATA for TREATMENT COHORT */
>data item1;
>input it1 x y; /* it1 is the propensity score for treatment cohort */
>cards; /* x is the member ID and y is anothre variable */
>0.55 1001 40
>0.54 1002 7
>0.20 1003 10
>0.88 1004 12
>1.40 1005 16
>;
>run;
>proc sort;by it1;run;
>
> /* DATA for COMPARISON COHORT */
>data item2;
>input it2 a b; /* it2 is the propensity score for comparison cohort */
>cards; /* a is the member ID and b is another variable */
>.25 2001 2
>.50 2002 3
>.75 2003 4
>1.00 2004 5
>1.25 2005 6
>1.50 2006 7
>1.75 2007 8
>0.55 2008 9
>;
>proc sort;by it2;run;
>
>data match (drop=it2 a b change diff);
> /* reads in each observation from ITEM1 dset */
> set item1;
> do i=1 to nobs;
> /* loops through every observation in ITEM2 dset */
> set item2 point=i nobs=nobs;
> /* create and retain temporary variables */
> retain change newit2 newa newb;
> diff=abs(it1-it2);
> /* set values of temp vars in first iteration of DO
>loop */
> if i=1 then
> do;
> change=diff;
> newit2=it2;
> newa=a;
> newb=b;
> end;
> /* compare values of diff and change, and output
>accordingly */
> else if diff le change then
> do;
> change=diff;
> newit2=it2;
> newa=a;
> newb=b;
> end;
> else
> do;
> if diff ge change then
> do;
> output;
> leave;
> end;
> end;
> end;
>
> rename newa=a newb=b newit2=it2;
>run;
>
>proc print; run;