Need help to flag encounters inside other encountes

Reply
Occasional Contributor
Posts: 5

Need help to flag encounters inside other encountes

Hello!

I need help to flag where admission and discharge dates are within each other.

For example:

MHN         ADMITDATE            DISCHARGEDATE           FLAG

111           1/5/2013                   1/10/2013

111           1/7/2013                   1/8/2013                              1

111           2/3/2013                   2/4/2013

222           2/10/2013                 2/15/2013       

222           2/10/2013                 2/10/2013                            1

222           2/14/2013                 2/14/2013                            1

444           5/10/2013                 5/11/2013

So I would need a field called flag and I would need to flag the three that I have put a 1 by.  Is this possible?

Thank you so much in advance!

Respected Advisor
Posts: 4,925

Re: Need help to flag encounters inside other encountes

Posted in reply to sashelpwanted

DO UNTIL to the rescue:

data have;

input MHN  ADMITDATE :mmddyy. DISCHARGEDATE :mmddyy.;

format admitdate dischargedate yymmdd.;

datalines;

111           1/5/2013                   1/10/2013

111           1/7/2013                   1/8/2013                             

111           2/3/2013                   2/4/2013

222           2/10/2013                 2/15/2013      

222           2/10/2013                 2/10/2013                           

222           2/14/2013                 2/14/2013                           

444           5/10/2013                 5/11/2013

;

data want;

do until(last.mhn);

  set have; by mhn;

  flag = admitdate < lastdischarge;

  output;

  lastdischarge = max(lastdischarge, dischargedate);

  end;

drop lastdischarge;

run;

proc print data=want noobs; run;

PG

PG
Frequent Contributor
Posts: 106

Re: Need help to flag encounters inside other encountes

Posted in reply to sashelpwanted

why 111  1/7/2013  1/8/2013      this line has flag 1 and why not  111 2/3/2013  2/4/2013, they also have diff of 1.

or may be you just want to check when admission date and discharge date are same, then you may try below code:


data have;

input MHN  ADMITDATE :mmddyy. DISCHARGEDATE :mmddyy.;

format admitdate dischargedate yymmdd.;

if ADMITDATE= DISCHARGEDATE then flag=1;

datalines;

111           1/5/2013                   1/10/2013

111           1/7/2013                   1/8/2013                           

111           2/3/2013                   2/4/2013

222           2/10/2013                 2/15/2013    

222           2/10/2013                 2/10/2013                         

222           2/14/2013                 2/14/2013                         

444           5/10/2013                 5/11/2013

;

RUN;

Ask a Question
Discussion stats
  • 2 replies
  • 171 views
  • 0 likes
  • 3 in conversation