** WhoCD4atARVstart.sas ** ; ** Following is the SAS code for standardizing the selection of the CD4 and WHO Stage at therapeutic ART initiation. ** Replace visitds with appropriate longitudinal dataset that contains CD4, cd4date, whostage, ptidno, apptdate, and arvstart. ** Please use this code unless otherwise directed. ** August 4, 2009 BSM ************************** ; ** CD4 at ARV Start - identifies CD4 within 90 days prior and 7 days post therapeutic ART initiation. ** If multiple CD4s, use the one closest to start of arvs ** ; data cd4everon ; set visitds ; if cd4 ne . ; diffcd4arv = arvstartTHERAP-cd4date ; if -8 < diffcd4arv < 91 ; absdiff = abs(diffcd4arv) ; run ; proc sort data=cd4everon ; by ptidno absdiff ; data cd4on(keep=ptidno cd4atarvstart) ; set cd4everon(rename=cd4=cd4atarvstart) ; by ptidno absdiff ; if first.ptidno ; label cd4atarvstart='CD4 at therapeutic ARV start(90 days pre - 7 post)' ; run ; ** WHO Stage at ARV start - identifies WHO stage at ART initiation which is the maximum WHO stage prior to ARV start assuming that WHO stage should ** not be down graded. If there are no WHO stages recorded prior to ART initiation, use closest stage within 60 days after initiation. ** May need to investigate patients who have a single observation with WHO stage 3 or 4 and all other visits with WHO stage 1 or 2 ** ; data whostagemax whoafter ; set visitds ; if whostage ne . and apptdate le arvstartTHERAP then output whostagemax ; else if whostage ne . and arvstartTHERAP ne . and arvstartTHERAP < apptdate <= arvstartTHERAP + 60 then output whoafter ; keep ptidno apptdate whostage ; run ; proc sort data=whostagemax ; by ptidno whostage ; data whomaxa ; set whostagemax ; by ptidno whostage ; if last.ptidno ; run ; ** if no WHO stage prior to ART initiation, use closest within 60 days after ** ; proc sort data=whoafter ; by ptidno apptdate ; data whoafter1 ; set whoafter ; by ptidno apptdate ; if first.ptidno ; run ; data whomax ; merge whomaxa(rename=whostage=whoatarvstart) whoafter1(rename=whostage=whoafter) ; by ptidno ; if whoatarvstart=. then whoatarvstart=whoafter ; drop whoafter ; label whoatarvstart='Maximum WHO Stage prior to therapeutic ARV start or first within 60 days post' ; run ;