## Find individuals with multiple encounters and same diagnosis on a rolling basis

Solved
Occasional Contributor
Posts: 11

# Find individuals with multiple encounters and same diagnosis on a rolling basis

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.

Accepted Solutions
Solution
‎12-22-2015 01:54 PM
Posts: 5,529

## Re: Find individuals with multiple encounters and same diagnosis on a rolling basis

Couldn't do any testing, but this should be close:

``````data diag140106_350;
set caper140106_350xx_sort;
array d{*} dx1-dx5;
do i = 1 to dim(d);
diag = d{i};
if diag in (/* list of required diagnosis goes here */) then output;
end;
keep patssn encdate1 diag;
run;

proc sql;
create table diag3all as
select
a.patssn,
a.diag,
a.encDate1,
b.encDate1 as otherDate1,
count(distinct b.encDate1) + 1 as nbDiag
from
diag140106_350 as a inner join
diag140106_350 as b
on
a.patssn = b.patssn and
a.diag = b.diag and
a.encDate1 < b.encDate1 and
intck("month", a.encDate1, b.encDate1, "continuous") <= 6
group by a.patssn, a.diag, a.encDate1
having count(distinct b.encDate1) + 1 >= 3;

create table diag3 as
select *
from diag3all
group by patssn, diag
having nbDiag = max(nbDiag);
quit;``````
PG

All Replies
Solution
‎12-22-2015 01:54 PM
Posts: 5,529

## Re: Find individuals with multiple encounters and same diagnosis on a rolling basis

Couldn't do any testing, but this should be close:

``````data diag140106_350;
set caper140106_350xx_sort;
array d{*} dx1-dx5;
do i = 1 to dim(d);
diag = d{i};
if diag in (/* list of required diagnosis goes here */) then output;
end;
keep patssn encdate1 diag;
run;

proc sql;
create table diag3all as
select
a.patssn,
a.diag,
a.encDate1,
b.encDate1 as otherDate1,
count(distinct b.encDate1) + 1 as nbDiag
from
diag140106_350 as a inner join
diag140106_350 as b
on
a.patssn = b.patssn and
a.diag = b.diag and
a.encDate1 < b.encDate1 and
intck("month", a.encDate1, b.encDate1, "continuous") <= 6
group by a.patssn, a.diag, a.encDate1
having count(distinct b.encDate1) + 1 >= 3;

create table diag3 as
select *
from diag3all
group by patssn, diag
having nbDiag = max(nbDiag);
quit;``````
PG
🔒 This topic is solved and locked.