BookmarkSubscribeRSS Feed
sashelpwanted
Calcite | Level 5

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!

2 REPLIES 2
PGStats
Opal | Level 21

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
pradeepalankar
Obsidian | Level 7

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 929 views
  • 0 likes
  • 3 in conversation