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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 378 views
  • 0 likes
  • 3 in conversation