DATA Step, Macro, Functions and more

flagging dianosis during study period

Reply
Contributor
Posts: 29

flagging dianosis during study period

Hi I want to flag diagnosis codes during defined study period

 

DM dignosis   pt ID        From_dt            To-Dt

1 (yes)            1          2005-04-02       2006-05-20

2(yes)              2        2001-01-01        2001-01-02

 

Study period   index_dt               end_dt

                       2004-04-01         2007-01-10

 

I want my result to look like;

 

Pt ID      eligible

1             yes

2            no

 

Thanks

 

 

Super User
Super User
Posts: 9,789

Re: flagging dianosis during study period

Post test data in the form of a datastep.  I haven't time to type that in or guess what formats etc the table has.  So at a rough guess:

proc sql;
  create table WANT as
  select  A.PT_ID,
          case when A.FROM_DT <= B.END_DT and A.TO_DT > B.INDEX_DT then "yes" else "no" end as ELIGIBLE
  from    HAVE1 A
  left join HAVE2 B
  on      1=1;
quit;

You can do the same thing in datastep merge also, basically your merging the dates dataset onto the main one, then doing an if between the two dates.

Contributor
Posts: 29

Re: flagging dianosis during study period

Hi,

I need to clarify my initial question. It had mistakes. My variables are all from the same dataset and dates are already SAS dates

 

So

DM_diagnosis  pt ID  from_dt (diag)           To_dt   (diag)           Index_dt             end_dt

1  (yes)              1      2005-04-02           2006-05-20                2004-04-01          2007-01-10

1  (yes)              2      2001-01-01           2001-01-02                2003-04-01          2003-12-10

 

Output

Pt ID   eligible

1          yes

2         no

 

Thanks

Super User
Super User
Posts: 9,789

Re: flagging dianosis during study period

Even simpler then, you just need the if statements:

data want;
  set have;
  if from_dt <= end_dt and to_dt >= index_dt then eligible="yes";
  else eligible="no";
run;
Super User
Posts: 13,868

Re: flagging dianosis during study period


leahcho wrote:

Hi,

I need to clarify my initial question. It had mistakes. My variables are all from the same dataset and dates are already SAS dates

 

So

DM_diagnosis  pt ID  from_dt (diag)           To_dt   (diag)           Index_dt             end_dt

1  (yes)              1      2005-04-02           2006-05-20                2004-04-01          2007-01-10

1  (yes)              2      2001-01-01           2001-01-02                2003-04-01          2003-12-10

 

Output

Pt ID   eligible

1          yes

2         no

 

Thanks


You may need to provide some additional rules. Is it within study period if the from_dt is prior to the index date but the to_dt is in the interval?

If the from_dt is before and To_dt is past the end_dt (the study interval is within the diag interval)

How about the from_dt is in the interval but  the to_dt is past the end_dt?

Contributor
Posts: 29

Re: flagging dianosis during study period

I want diagnosis interval to fall within study interval

 

Thanks

Ask a Question
Discussion stats
  • 5 replies
  • 106 views
  • 0 likes
  • 3 in conversation