BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
janet0102
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

View solution in original post

1 REPLY 1
PGStats
Opal | Level 21

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 476 views
  • 0 likes
  • 2 in conversation