<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Propensity score match with replacement in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Propensity-score-match-with-replacement/m-p/318380#M16796</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Does anyone know if there are any macro for propensity score matching with replacement, where you&amp;nbsp; have on option to limit (set a maxium value) the number of times a subject can be a control?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Thomas&lt;/P&gt;</description>
    <pubDate>Mon, 12 Dec 2016 21:18:56 GMT</pubDate>
    <dc:creator>bollibompa</dc:creator>
    <dc:date>2016-12-12T21:18:56Z</dc:date>
    <item>
      <title>Propensity score match with replacement</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Propensity-score-match-with-replacement/m-p/318380#M16796</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Does anyone know if there are any macro for propensity score matching with replacement, where you&amp;nbsp; have on option to limit (set a maxium value) the number of times a subject can be a control?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Thomas&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2016 21:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Propensity-score-match-with-replacement/m-p/318380#M16796</guid>
      <dc:creator>bollibompa</dc:creator>
      <dc:date>2016-12-12T21:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: Propensity score match with replacement</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Propensity-score-match-with-replacement/m-p/320487#M16925</link>
      <description>&lt;P&gt;Hi again,&lt;/P&gt;
&lt;P&gt;Marcelo Coca-Perraillon has developed a PS macro where you can match with replacement. It uses hash-programming not so familiar to me. I attch the whole macro at the end of this message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this macro you can specify if you would like to match with or without replacement. Does anyone have a suggestion how you can update this macro so you only can use each control a maximum number of times (e.g. 10 times)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this code-part the macro removes the control if you match without replacement (=NO). I am trying to modify the code by including a AND-statement like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if %upcase(&amp;amp;replacement)=YES AND (IdSelectedControl + &lt;STRONG&gt;something like : occurs &amp;lt; 10 times&lt;/STRONG&gt;) %then %do rc1=h.remove(key:IdSelectedControl);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%if %upcase(&amp;amp;replacement) = NO %then %do;
rc1 = h.remove(key: IdSelectedControl);
%end;
end;
%end;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for help on this!&lt;/P&gt;
&lt;P&gt;/Thomas&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro PSMatching(datatreatment=, datacontrol=, method=, numberofcontrols=, caliper=,
 replacement=, out=);

/* Create copies of the treated units if N &amp;gt; 1 */;
 data _Treatment0(drop= i);
  set &amp;amp;datatreatment;
  do i= 1 to &amp;amp;numberofcontrols;
  RandomNumber= ranuni(12345);
output;
end;
run;
/* Randomly sort both datasets */
proc sort data= _Treatment0 out= _Treatment(drop= RandomNumber);
by RandomNumber;
run;
data _Control0;
set &amp;amp;datacontrol;
RandomNumber= ranuni(45678);
run;
proc sort data= _Control0 out= _Control(drop= RandomNumber);
by RandomNumber;
run;

 data Matched(keep = IdSelectedControl PScoreControl MatchedToTreatID PScoreTreat);
  length pscoreC 8;
  length idC 8;
/* Load Control dataset into the hash object */
  if _N_= 1 then do;
declare hash h(dataset: "_Control", ordered: 'no');
declare hiter iter('h');
h.defineKey('idC');
h.defineData('pscoreC', 'idC');
h.defineDone();
call missing(idC, pscoreC);
end;
/* Open the treatment */
set _Treatment;
%if %upcase(&amp;amp;method) ~= RADIUS %then %do;
retain BestDistance 99;
%end;
/* Iterate over the hash */
rc= iter.first();
if (rc=0) then BestDistance= 99;
do while (rc = 0);
/* Caliper */
%if %upcase(&amp;amp;method) = CALIPER %then %do;
if (pscoreT - &amp;amp;caliper) &amp;lt;= pscoreC &amp;lt;= (pscoreT + &amp;amp;caliper) then do;
ScoreDistance = abs(pscoreT - pscoreC);
if ScoreDistance &amp;lt; BestDistance then do;
BestDistance = ScoreDistance;
IdSelectedControl = idC;
PScoreControl =  pscoreC;
MatchedToTreatID = idT;
PScoreTreat = pscoreT;
end;
end;
%end;
/* NN */
%if %upcase(&amp;amp;method) = NN %then %do;
ScoreDistance = abs(pscoreT - pscoreC);
if ScoreDistance &amp;lt; BestDistance then do;
BestDistance = ScoreDistance;
IdSelectedControl = idC;
PScoreControl =  pscoreC;
MatchedToTreatID = idT;
PScoreTreat = pscoreT;
end;
%end;

%if %upcase(&amp;amp;method) = NN or %upcase(&amp;amp;method) = CALIPER %then %do;
rc = iter.next();
/* Output the best control and remove it */
if (rc ~= 0) and BestDistance ~=99 then do;
output;
%if %upcase(&amp;amp;replacement) = NO %then %do;
rc1 = h.remove(key: IdSelectedControl);
%end;
end;
%end;
/* Radius */
%if %upcase(&amp;amp;method) = RADIUS %then %do;
if (pscoreT - &amp;amp;caliper) &amp;lt;= pscoreC &amp;lt;= (pscoreT + &amp;amp;caliper) then do;
IdSelectedControl = idC;
PScoreControl =  pscoreC;
MatchedToTreatID = idT;
PScoreTreat = pscoreT;
output;
end;
rc = iter.next();
%end;
end;
run;
/* Delete temporary tables. Quote for debugging */
proc datasets;
delete _:(gennum=all);

run;
 data &amp;amp;out;
   set Matched;
 run;
%mend PSMatching;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 12:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Propensity-score-match-with-replacement/m-p/320487#M16925</guid>
      <dc:creator>bollibompa</dc:creator>
      <dc:date>2016-12-21T12:18:21Z</dc:date>
    </item>
  </channel>
</rss>

