DATA Step, Macro, Functions and more

Retain Timestamp

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

Retain Timestamp

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

 

 


Accepted Solutions
Solution
‎10-17-2017 08:41 AM
Super User
Super User
Posts: 9,200

Re: Retain Timestamp

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;

View solution in original post


All Replies
Solution
‎10-17-2017 08:41 AM
Super User
Super User
Posts: 9,200

Re: Retain Timestamp

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;
Contributor
Posts: 39

Re: Retain Timestamp

Thank you, I realized this that I should have codes in my post after I posted. Thanks again.

Contributor
Posts: 39

Re: Retain Timestamp

RW9, you solved my problem in such a simple way and I was making it so complicated. Today I realize the fact that we should not think too much every time. Thanks again
Super User
Super User
Posts: 9,200

Re: Retain Timestamp

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 ...

Contributor
Posts: 39

Re: Retain Timestamp

Okay, I got it.

Thank you!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 105 views
  • 0 likes
  • 2 in conversation