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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.