I'm attempting to find individuals with at least 3 medical encounters during a 6-month period with the same specified diagnosis codes in one of the first 5 diagnosis fields (dx1-dx5). One of my colleagues had code to do the same thing but only needed 2 medical encounters; I've attempted to adapt it: I first created a data set that included only individuals who had the desired diagnosis in one of the first 5 diagnosis fields and used that for the following: proc sql; create table caper140106_350_obs (drop=lo hi) as select a.patssn, a.edipn, a.appttype, a.encdate1 as encdate1_check, a.nobs as nobs_check, a.dx1 as dx1_check, a.dx2 as dx2_check, a.dx3 as dx3_check, a.dx4 as dx4_check, a.dx5 as dx5_check, b.encdate1 as encdate1_plus, b.nobs as nobs_plus, b.dx1 as dx1_plus, b.dx2 as dx2_plus, b.dx3 as dx3_plus, b.dx4 as dx4_plus, b.dx5 as dx5_plus, c.encdate1, c.nobs, c.dx1, c.dx3, c.dx4, c.dx5, intnx('month',a.encdate1,-6) as lo, intnx('month',a.encdate1,6) as hi, catx('',min(a.encdate1,c.encdate1), max(a.encdate1,c.encdate1))as minmax from caper140106_350xx_sort as a, caper140106_350xx_sort as b, caper140106_350xx_sort as c where a.patssn=b.patssn=c.patssn and (b.encdate1 & c.encdate1 between calculated lo and calculated hi) and a.nobs^=b.nobs^=c.nobs order patssn, encdate1_plus; quit; It runs, and I get results that appear to be correct, but I'm not confident that I actually have what I need. I started with 814 rows and the results gave me 79,278 rows. When I deduped the individuals, I end up with 148 people (probably reasonable). Secondary question: I have more than 25 specfic diagnosis codes that I need to do this for. Do I need to create a data set for each of the diagnoses first and then find individuals with multiple encounters or is there a way to find folks with the multiple encounters and then pull my diagnosis codes? I really appreciate any help with this.
... View more