Hello-
I wish to compute length of stay for each observation by subtracting ADT_IN from ADR_OUT.
Please help me with the code
ADT_IN | ADT_OUT |
2/9/2017 19:50 | 2/10/2017 14:21 |
2/8/2017 17:50 | 2/10/2017 12:40 |
2/7/2017 11:43 | 2/9/2017 12:50 |
2/8/2017 12:56 | 2/11/2017 0:42 |
2/8/2017 12:56 | 2/11/2017 0:42 |
2/8/2017 12:56 | 2/11/2017 0:42 |
2/8/2017 12:56 | 2/11/2017 0:42 |
2/8/2017 12:56 | 2/11/2017 0:42 |
2/8/2017 12:56 | 2/11/2017 0:42 |
data have;
input (ADT_IN ADT_OUT)(:mdyampm. &);
format ADT_IN ADT_OUT datetime.;
cards;
2/9/2017 19:50 2/10/2017 14:21
2/8/2017 17:50 2/10/2017 12:40
2/7/2017 11:43 2/9/2017 12:50
2/8/2017 12:56 2/11/2017 0:42
2/8/2017 12:56 2/11/2017 0:42
2/8/2017 12:56 2/11/2017 0:42
2/8/2017 12:56 2/11/2017 0:42
2/8/2017 12:56 2/11/2017 0:42
2/8/2017 12:56 2/11/2017 0:42
;
data want;
set have;
/* This code doesn't take into account whether or not adding 1 to the result. */
LOS = datepart(ADT_OUT) - datepart(ADT_IN);
run;
Hello-
I wish to compute length of stay for each observation by subtracting ADT_IN from ADR_OUT.
Please help me with the code
data;
input ADT_IN ADT_OUT;
Cards;
2/9/2017 19:50 2/10/2017 14:21
2/8/2017 17:50 2/10/2017 12:40
;
run;
Each that has an associated time to it.
I've merged your two posts since they're the same. What have you tried so far? Post any code that you've attempted to date.
Hint, try INTCK and/or direct subtraction.
There's a tutorial on dates and times here:
Edit: Unfortunately your data step appears incorrect, instructions on posting data is here.
Thank you. I didnt meant to post it twice. The first was showing error messages when pasted
data have;
input (ADT_IN ADT_OUT)(:mdyampm. &);
format ADT_IN ADT_OUT datetime.;
cards;
2/9/2017 19:50 2/10/2017 14:21
2/8/2017 17:50 2/10/2017 12:40
2/7/2017 11:43 2/9/2017 12:50
2/8/2017 12:56 2/11/2017 0:42
2/8/2017 12:56 2/11/2017 0:42
2/8/2017 12:56 2/11/2017 0:42
2/8/2017 12:56 2/11/2017 0:42
2/8/2017 12:56 2/11/2017 0:42
2/8/2017 12:56 2/11/2017 0:42
;
data want;
set have;
/* This code doesn't take into account whether or not adding 1 to the result. */
LOS = datepart(ADT_OUT) - datepart(ADT_IN);
run;
Thank you!
I edited and added a information in my initial post.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.