Good Morning all,
Below is my data. I just wanted to retain extubation timestamp. For patients who had extubated once I am able to retain their extubation time but there are some patients who extubated more than once during their admission (means they got intubated twice). Below is an example of such patients and I want to retain ext_ts as shown in last column.
Thanks in advance.
Encounter | Date | ICU | Icu_stay | Admit_ts | Discharge_ts | EXT_TS | ext_ts2 | ts_ext |
A | 9/30/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | 30SEP16:09:15:00 | 1 | 30SEP16:09:15:00 |
A | 10/1/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | . | . | 30SEP16:09:15:01 |
A | 10/2/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | . | . | 30SEP16:09:15:02 |
A | 10/3/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | . | . | 30SEP16:09:15:03 |
A | 10/4/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | . | . | 30SEP16:09:15:04 |
A | 10/5/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | . | . | 30SEP16:09:15:05 |
A | 10/6/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | 06OCT16:10:03:00 | 2 | 06OCT16:10:03:00 |
A | 10/7/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | . | . | 06OCT16:10:03:01 |
A | 10/8/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | . | . | 06OCT16:10:03:02 |
A | 10/9/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | . | . | 06OCT16:10:03:03 |
A | 10/10/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | . | . | 06OCT16:10:03:04 |
A | 10/11/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | . | . | 06OCT16:10:03:05 |
A | 10/12/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | . | . | 06OCT16:10:03:06 |
A | 10/13/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | . | . | 06OCT16:10:03:07 |
A | 10/14/2016 | East ICU | 1 | 29SEP16:14:20:00 | 14OCT16:20:00:00 | . | . | 06OCT16:10:03:08 |
B | 9/20/2016 | East ICU | 1 | 13SEP16:01:45:00 | 23SEP16:22:25:00 | 20SEP16:12:45:00 | 1 | 20SEP16:12:45:00 |
B | 9/21/2016 | East ICU | 1 | 13SEP16:01:45:00 | 23SEP16:22:25:00 | . | . | 20SEP16:12:45:01 |
B | 9/22/2016 | East ICU | 1 | 13SEP16:01:45:00 | 23SEP16:22:25:00 | . | . | 20SEP16:12:45:02 |
B | 9/23/2016 | East ICU | 1 | 13SEP16:01:45:00 | 23SEP16:22:25:00 | . | . | 20SEP16:12:45:03 |
B | 9/25/2016 | East ICU | 2 | 25SEP16:21:44:00 | 29SEP16:19:04:00 | . | . | 20SEP16:12:45:04 |
B | 9/26/2016 | East ICU | 2 | 25SEP16:21:44:00 | 29SEP16:19:04:00 | . | . | 20SEP16:12:45:05 |
B | 9/27/2016 | East ICU | 2 | 25SEP16:21:44:00 | 29SEP16:19:04:00 | 27SEP16:19:04:00 | 2 | 27SEP16:19:04:00 |
B | 9/28/2016 | East ICU | 2 | 25SEP16:21:44:00 | 29SEP16:19:04:00 | . | . | 27SEP16:19:04:01 |
B | 9/29/2016 | East ICU | 2 | 25SEP16:21:44:00 | 29SEP16:19:04:00 | . | . | 27SEP16:19:04:02 |
I am not here to type test data in, so this code is untested:
data want (drop=tmp); set have; retain tmp; if ext_ts ne . then tmp=ext_ts; if ext_ts=. then ext_ts=tmp; run;
I am not here to type test data in, so this code is untested:
data want (drop=tmp); set have; retain tmp; if ext_ts ne . then tmp=ext_ts; if ext_ts=. then ext_ts=tmp; run;
Thank you, I realized this that I should have codes in my post after I posted. Thanks again.
One thing I would point out is that if the first ts in the group is null it will retain across from previous row. May not be an issue but if it is then put a by <group> and use that in the if's as well, i.e. if first.<group> then ...
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.