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!
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
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: