Inverse probability treatment weighting (IPTW) for continuous treatment

SAS Code to generate IPTW for continuous treatment duration



Donna L. Coffman, Daniel Almirall and Wei Zhong "Assessing mediation using marginal structural models in the presence of confounding and moderation" Penn State, Technical Report Series 11-112

Appendix (page 47) gives R code for empirical data analysis, which I have converted to SAS below:

*--- center the continuous treatment duration variable at zero;

proc standard data=mydata out=stddata mean=0;

var duration;


*--- intercept-only model for numerator;

ods output FitStatistics=fitnum;

proc reg data=stddata(keep=ptid duration);

model duration = ;

output out=ipt0 student=rd0 pred=yhat0;

run; quit;

data _null_; set fitnum;

if label1='Root MSE';

call symput('sigmani1',put(nvalue1,best.));


*--- full model for denominator;

ods output FitStatistics=fitden;

proc reg data=stddata(keep=ptid a b c d duration);

model duration = a b c d;

output out=ipt1 student=rd1 pred=yhat1;

run; quit;

data _null_; set fitden;

if label1='Root MSE';

call symput('sigmadi1',put(nvalue1,best.));


data ipt2; merge ipt0 ipt1;

by ptid;

sigmad=&sigmadi1; sigman=&sigmani1;



iptw = num_p/den_p;