BookmarkSubscribeRSS Feed
AMFR
Quartz | Level 8

Hello all,

 

My data looks like this.

EncounterDateCAM_TScamlag_camdel_over
A8/5/201805AUG18:20:45:00110
A8/6/201806AUG18:08:22:00110
A8/7/201807AUG18:09:00:00110
A8/8/201808AUG18:00:04:00110
A8/9/201809AUG18:08:01:00110
A8/10/201810AUG18:08:46:00110
A8/11/201811AUG18:12:23:00110
A8/12/201812AUG18:21:00:00110
A8/13/201813AUG18:09:19:00110
A8/14/201814AUG18:00:00:00011
A8/15/201815AUG18:00:00:00001
A8/16/201816AUG18:04:09:00001
A8/17/201817AUG18:00:00:00001
B10/8/2017...0
B10/9/201709OCT17:09:17:000.1
B10/10/2017..00
B10/11/2017...0
B10/12/201712OCT17:02:26:001.0
B10/13/201713OCT17:08:41:00011
B10/14/201714OCT17:08:46:00001
B10/15/201715OCT17:04:04:00100
B10/16/201716OCT17:20:16:00110
B10/17/201717OCT17:21:00:00011
B10/18/201718OCT17:21:30:00100
B10/19/201719OCT17:08:00:00110
B10/20/201720OCT17:00:07:00110
B10/21/201721OCT17:00:00:00110
B10/22/201722OCT17:21:32:00110
B10/23/201723OCT17:21:00:00011
B10/24/201724OCT17:08:12:00001

 

I have a data where I have to find when patient is out of delirium, two consecutive cam should be 0. First we need to extract those first two cam_ts when two consecutive cam=0. For example for encounter A the first two consecutive cam_ts when cam=0 would be on 14th Aug and 15th Aug, and after that I need to write a piece of code that would give me the output of the data before two consecutive cam=0. And I only need to look at the first two consecutive cam=0. For example encounter B has two time consecutive cam=0, we would consider delirium is over after first two consecutive cam=0.

Please ignore lag_cam and del_over columns. These are the columns I created to solve my question but it didn't help

 

Hope I am making sense, any help would be greatly appreciated.

Thanks

 

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Hi @AMFR  Assuming I understand

 



data have;
input Encounter	$ Date :mmddyy10.	CAM_TS :datetime20.	cam	lag_cam;
format date mmddyy10. CAM_TS datetime20.;
cards;
A	8/5/2018	05AUG18:20:45:00	1	1
A	8/6/2018	06AUG18:08:22:00	1	1
A	8/7/2018	07AUG18:09:00:00	1	1
A	8/8/2018	08AUG18:00:04:00	1	1
A	8/9/2018	09AUG18:08:01:00	1	1
A	8/10/2018	10AUG18:08:46:00	1	1
A	8/11/2018	11AUG18:12:23:00	1	1
A	8/12/2018	12AUG18:21:00:00	1	1
A	8/13/2018	13AUG18:09:19:00	1	1
A	8/14/2018	14AUG18:00:00:00	0	1
A	8/15/2018	15AUG18:00:00:00	0	0
A	8/16/2018	16AUG18:04:09:00	0	0
A	8/17/2018	17AUG18:00:00:00	0	0
B	10/8/2017	.	.	.
B	10/9/2017	09OCT17:09:17:00	0	.
B	10/10/2017	.	.	0
B	10/11/2017	.	.	.
B	10/12/2017	12OCT17:02:26:00	1	.
B	10/13/2017	13OCT17:08:41:00	0	1
B	10/14/2017	14OCT17:08:46:00	0	0
B	10/15/2017	15OCT17:04:04:00	1	0
B	10/16/2017	16OCT17:20:16:00	1	1
B	10/17/2017	17OCT17:21:00:00	0	1
B	10/18/2017	18OCT17:21:30:00	1	0
B	10/19/2017	19OCT17:08:00:00	1	1
B	10/20/2017	20OCT17:00:07:00	1	1
B	10/21/2017	21OCT17:00:00:00	1	1
B	10/22/2017	22OCT17:21:32:00	1	1
B	10/23/2017	23OCT17:21:00:00	0	1
B	10/24/2017	24OCT17:08:12:00	0	0
;


data want;
 set have;
 by encounter cam notsorted;
 retain del_over;
 if first.cam then del_over=0;
 if not (first.cam and last.cam) and cam=0 then del_over=1;
run;
AMFR
Quartz | Level 8

Thank you very much, after identifying when delirium is over, this is exactly what I was doing created lag_cam and del_over.

After that in first step I want to have data look like this.

EncounterDateCAM_TScamdel_overFirst_del_over_tsSecond_Del_over_ts
A8/5/201805AUG18:20:45:001014AUG18:00:00:0015AUG18:00:00:00
A8/6/201806AUG18:08:22:001014AUG18:00:00:0115AUG18:00:00:01
A8/7/201807AUG18:09:00:001014AUG18:00:00:0215AUG18:00:00:02
A8/8/201808AUG18:00:04:001014AUG18:00:00:0315AUG18:00:00:03
A8/9/201809AUG18:08:01:001014AUG18:00:00:0415AUG18:00:00:04
A8/10/201810AUG18:08:46:001014AUG18:00:00:0515AUG18:00:00:05
A8/11/201811AUG18:12:23:001014AUG18:00:00:0615AUG18:00:00:06
A8/12/201812AUG18:21:00:001014AUG18:00:00:0715AUG18:00:00:07
A8/13/201813AUG18:09:19:001014AUG18:00:00:0815AUG18:00:00:08
A8/14/201814AUG18:00:00:000114AUG18:00:00:0915AUG18:00:00:09
A8/15/201815AUG18:00:00:000114AUG18:00:00:1015AUG18:00:00:10
A8/16/201816AUG18:04:09:000114AUG18:00:00:1115AUG18:00:00:11
A8/17/201817AUG18:00:00:000114AUG18:00:00:1215AUG18:00:00:12
B10/8/2017..013OCT17:08:41:0014OCT17:08:46:00
B10/9/201709OCT17:09:17:000113OCT17:08:41:0114OCT17:08:46:01
B10/10/2017..013OCT17:08:41:0214OCT17:08:46:02
B10/11/2017..013OCT17:08:41:0314OCT17:08:46:03
B10/12/201712OCT17:02:26:001013OCT17:08:41:0414OCT17:08:46:04
B10/13/201713OCT17:08:41:000113OCT17:08:41:0514OCT17:08:46:05
B10/14/201714OCT17:08:46:000113OCT17:08:41:0614OCT17:08:46:06
B10/15/201715OCT17:04:04:001013OCT17:08:41:0714OCT17:08:46:07
B10/16/201716OCT17:20:16:001013OCT17:08:41:0814OCT17:08:46:08
B10/17/201717OCT17:21:00:000113OCT17:08:41:0914OCT17:08:46:09
B10/18/201718OCT17:21:30:001013OCT17:08:41:1014OCT17:08:46:10
B10/19/201719OCT17:08:00:001013OCT17:08:41:1114OCT17:08:46:11
B10/20/201720OCT17:00:07:001013OCT17:08:41:1214OCT17:08:46:12
B10/21/201721OCT17:00:00:001013OCT17:08:41:1314OCT17:08:46:13
B10/22/201722OCT17:21:32:001013OCT17:08:41:1414OCT17:08:46:14
B10/23/201723OCT17:21:00:000113OCT17:08:41:1514OCT17:08:46:15
B10/24/201724OCT17:08:12:000113OCT17:08:41:1614OCT17:08:46:16

 

And after separating out the two consecutive TS when delirium is over, data should look like this because I don't want to include days after delirium is over.

 

EncounterDateCAM_TScamdel_overFirst_del_over_tsSecond_Del_over_ts
A8/5/201805AUG18:20:45:001014AUG18:00:00:0015AUG18:00:00:00
A8/6/201806AUG18:08:22:001014AUG18:00:00:0115AUG18:00:00:01
A8/7/201807AUG18:09:00:001014AUG18:00:00:0215AUG18:00:00:02
A8/8/201808AUG18:00:04:001014AUG18:00:00:0315AUG18:00:00:03
A8/9/201809AUG18:08:01:001014AUG18:00:00:0415AUG18:00:00:04
A8/10/201810AUG18:08:46:001014AUG18:00:00:0515AUG18:00:00:05
A8/11/201811AUG18:12:23:001014AUG18:00:00:0615AUG18:00:00:06
A8/12/201812AUG18:21:00:001014AUG18:00:00:0715AUG18:00:00:07
A8/13/201813AUG18:09:19:001014AUG18:00:00:0815AUG18:00:00:08
B10/8/2017..013OCT17:08:41:0014OCT17:08:46:00
B10/9/201709OCT17:09:17:000113OCT17:08:41:0114OCT17:08:46:01
B10/10/2017..013OCT17:08:41:0214OCT17:08:46:02
B10/11/2017..013OCT17:08:41:0314OCT17:08:46:03
B10/12/201712OCT17:02:26:001013OCT17:08:41:0414OCT17:08:46:04
novinosrin
Tourmaline | Level 20

Okay @AMFR   Try this

 



data want;
 set have;
 by encounter cam notsorted;
 if first.encounter then _iorc_=0;
 del_over= not (first.cam and last.cam) and cam=0;
 if del_over then _iorc_=1;
 if not _iorc_;
run;
novinosrin
Tourmaline | Level 20

If my understanding is correct, the previous doesn't require a RETAIN because of the boolean operation. Sorry about that. So a modified version would be

 


data want;
 set have;
 by encounter cam notsorted;
 if not (first.cam and last.cam) and cam=0 then del_over=1;else del_over=0;
run;

/*or*/

data want;
 set have;
 by encounter cam notsorted;
 del_over= not (first.cam and last.cam) and cam=0;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 390 views
  • 0 likes
  • 2 in conversation