BookmarkSubscribeRSS Feed
UcheOkoro
Lapis Lazuli | Level 10

Hello All,

 

Please, I need help with coding an algorithm for a categorical outcome variable. For this variable there should be 3 levels. They are 'no violation', 'time violation' and 'acuity violation'. The variables needed to code the outcome include acuity which has 5 level -listed as 1-5 (represents illness severity with 1 being the sickest), waiting time (time from patient arrival to time they were picked up by a provider), roomed time (time they were roomed for vitals) and seen time (time seen by provider). The roomed and seen time are both datetimes. 

If a patient was roomed before another patient with a longer waiting time and was seen by a physician earlier and the patient (the index patient) was sicker. This is not a violation. However, this patient will then be compared with the next 19 patients. If there is no violation, then it will be recorded as 'no violation'.

However, if a patient was roomed before another patient with a longer waiting time and was seen by a physician earlier and the patient with the longer waiting time had same acuity with the index patient, then this is a time violation.

Also, if a patient who is sicker is seen later than another patient with a longer waiting time, then it is an 'acuity violation'. I am having difficulty writing the code for comparing the index patient with the next 19 patients.

 

Please, kindly help.

 

Thank you

 

data CHERRYP.newdata4;
set CHERRYP.newdata3;
If lag(Roomed)>Roomed then roomed_before =1;
Else roomed_before =0;
If lag(provider_Assigned)>Provider_Assigned then Assigned_before =1;
Else Assigned_before =0;
waiting_time=( ( Provider_Assigned- Arrival)/60 );
lag_acuity=lag(acuity);
lag_roomed=lag(roomed);
lag_provider_assigned =lag(Provider_Assigned);
lag_waiting_time =lag(waiting_time);
format lag_roomed lag_provider_assigned DATETIME.;RUN;


Data CHERRYP.Newdata5;
Set CHERRYP.Newdata4;
if roomed_before=1 and assigned_before=1 and acuity<lag_acuity and waiting_time<lag_waiting_time then Violation=0;
if roomed_before=1 and assigned_before=1 and acuity<lag_acuity and waiting_time>lag_waiting_time then Violation=0;
if roomed_before=1 and assigned_before=1 and acuity=lag_acuity and waiting_time<lag_waiting_time then Violation=2;
if roomed_before=1 and assigned_before=1 and acuity=lag_acuity and waiting_time>lag_waiting_time then Violation=0;
if roomed_before=1 and assigned_before=0 and acuity=lag_acuity and waiting_time<lag_waiting_time then Violation=0;
if roomed_before=1 and assigned_before=0 and acuity<lag_acuity and waiting_time>lag_waiting_time then Violation=1;
if roomed_before=1 and assigned_before=0 and acuity>lag_acuity and waiting_time>lag_waiting_time then Violation=0;
if roomed_before=1 and assigned_before=0 and acuity=lag_acuity and waiting_time>lag_waiting_time then Violation=2;
if roomed_before=0 and assigned_before=1 and acuity=lag_acuity and waiting_time<lag_waiting_time then Violation=2;
if roomed_before=0 and assigned_before=1 and acuity<lag_acuity and waiting_time<lag_waiting_time then Violation=0;
if roomed_before=0 and assigned_before=1 and acuity>lag_acuity and waiting_time<lag_waiting_time then Violation=0;
if roomed_before=0 and assigned_before=1 and acuity<lag_acuity and waiting_time<lag_waiting_time then Violation=0;
if roomed_before=0 and assigned_before=0 and acuity<lag_acuity and waiting_time<lag_waiting_time then Violation=1;
if roomed_before=0 and assigned_before=0 and acuity<lag_acuity and waiting_time>lag_waiting_time then Violation=1;
if roomed_before=0 and assigned_before=0 and acuity=lag_acuity and waiting_time<lag_waiting_time then Violation=0;
if roomed_before=0 and assigned_before=0 and acuity=lag_acuity and waiting_time>lag_waiting_time then Violation=1;run;
**Violation=1 is 'acuity violation', violation=2 is 'time violation' and acuity=0 is 'no violation'
2 REPLIES 2
PaigeMiller
Diamond | Level 26

I don't see anywhere that you are even trying to compare the index patient to the next 19 patients.

 

I think we would need to see a portion of the data in order to write code that works. Please provide the data as working SAS data step code (instructions) and not as Excel files or screen captures.

 

 

--
Paige Miller
UcheOkoro
Lapis Lazuli | Level 10
data dataset;
  infile datalines;
  input Acuity Roomed:$40. Provider_Assigned:$40. waiting_time;
       
datalines;
 3 01JUN19:00:09:00 01JUN19:00:14:00 70 
 3 01JUN19:00:21:00 01JUN19:00:28:00 225 
 2 01JUN19:00:40:00 01JUN19:00:44:00 122 
 3 01JUN19:00:39:00 01JUN19:00:44:00 9 
 2 01JUN19:00:39:00 01JUN19:00:47:00 279 
 3 01JUN19:01:14:00 01JUN19:01:14:00 11 
 4 01JUN19:01:13:00 01JUN19:01:28:00 69 
 2 01JUN19:01:08:00 01JUN19:01:17:00 22 
 2 01JUN19:01:17:00 01JUN19:01:18:00 5 
 3 01JUN19:01:21:00 01JUN19:01:47:00 544 
 2 01JUN19:01:57:00 01JUN19:01:59:00 5 
 2 01JUN19:01:45:00 01JUN19:01:56:00 11 
 2 01JUN19:01:55:00 01JUN19:02:11:00 185 
 3 01JUN19:02:04:00 01JUN19:02:08:00 21 
 3 01JUN19:02:04:00 01JUN19:02:08:00 21 
 2 01JUN19:02:07:00 01JUN19:02:10:00 9 
 2 01JUN19:02:07:00 01JUN19:02:10:00 9 
 3 01JUN19:02:28:00 01JUN19:02:32:00 6 
 3 01JUN19:02:28:00 01JUN19:02:32:00 6 
 2 01JUN19:02:33:00 01JUN19:02:31:00 10 
 2 01JUN19:02:58:00 01JUN19:03:03:00 5 
 3 01JUN19:02:46:00 01JUN19:03:06:00 20 
 4 01JUN19:03:22:00 01JUN19:03:24:00 22 
 4 01JUN19:03:22:00 01JUN19:03:24:00 22 
 2 01JUN19:03:20:00 01JUN19:03:24:00 7 
 2 01JUN19:03:51:00 01JUN19:03:52:00 136 
 3 01JUN19:04:34:00 01JUN19:04:38:00 661 
 3 01JUN19:04:36:00 01JUN19:04:39:00 644 
 3 01JUN19:04:36:00 01JUN19:04:47:00 616 
 3 01JUN19:04:37:00 01JUN19:04:55:00 374 
 3 01JUN19:05:11:00 01JUN19:05:12:00 459 
 3 01JUN19:04:57:00 01JUN19:05:28:00 631 
 2 01JUN19:05:28:00 01JUN19:05:34:00 13 
 4 01JUN19:05:51:00 01JUN19:06:01:00 203 
 1 01JUN19:06:06:00 01JUN19:06:18:00 15 
 2 01JUN19:06:08:00 01JUN19:06:30:00 25 
 2 01JUN19:06:08:00 01JUN19:06:30:00 25 
 3 01JUN19:06:14:00 01JUN19:06:55:00 190 
 2 01JUN19:07:01:00 01JUN19:07:15:00 15 
 3 01JUN19:05:43:00 01JUN19:07:44:00 122 
 3 01JUN19:05:43:00 01JUN19:07:44:00 122 
 3 01JUN19:07:20:00 01JUN19:07:30:00 108 
 4 01JUN19:07:28:00 01JUN19:07:30:00 32 
 3 01JUN19:07:34:00 01JUN19:07:37:00 48 
 3 01JUN19:07:31:00 01JUN19:07:59:00 79 
 4 01JUN19:07:28:00 01JUN19:08:11:00 73 
 3 01JUN19:08:03:00 01JUN19:08:20:00 79 
 3 01JUN19:08:05:00 01JUN19:08:20:00 34 
 3 01JUN19:07:08:00 01JUN19:08:40:00 95 
 2 01JUN19:08:34:00 01JUN19:08:39:00 6 
 3 01JUN19:08:32:00 01JUN19:09:00:00 72 
 3 01JUN19:08:55:00 01JUN19:09:01:00 56 
 3 01JUN19:08:58:00 01JUN19:09:01:00 40 
 3 01JUN19:09:02:00 01JUN19:09:26:00 44 
 4 01JUN19:09:25:00 01JUN19:09:26:00 13 
 3 01JUN19:09:19:00 01JUN19:09:24:00 6 
 3 01JUN19:09:12:00 01JUN19:09:42:00 40 
 3 01JUN19:09:18:00 01JUN19:09:45:00 40 
 3 01JUN19:09:35:00 01JUN19:10:04:00 39 
 3 01JUN19:09:52:00 01JUN19:10:24:00 34 
 4 01JUN19:09:44:00 01JUN19:10:31:00 69 
 3 01JUN19:10:07:00 01JUN19:10:47:00 54 
 3 01JUN19:11:02:00 01JUN19:11:06:00 12 
 2 01JUN19:11:31:00 01JUN19:11:42:00 18 
 3 01JUN19:11:21:00 01JUN19:11:58:00 44 
 3 01JUN19:11:26:00 01JUN19:11:55:00 39 
 3 01JUN19:11:26:00 01JUN19:12:00:00 42 
 3 01JUN19:11:26:00 01JUN19:12:02:00 40 
 3 01JUN19:11:26:00 01JUN19:12:02:00 40 
 2 01JUN19:11:41:00 01JUN19:12:24:00 44 
 . 01JUN19:11:59:00 01JUN19:12:17:00 19 
 3 01JUN19:12:00:00 01JUN19:12:22:00 23 
 3 01JUN19:12:00:00 01JUN19:12:22:00 23 
 2 01JUN19:12:15:00 01JUN19:12:24:00 19 
 3 01JUN19:11:47:00 01JUN19:12:47:00 66 
 3 01JUN19:12:12:00 01JUN19:12:56:00 51 
 4 01JUN19:12:24:00 01JUN19:12:58:00 46 
 3 01JUN19:12:28:00 01JUN19:12:47:00 26 
 3 01JUN19:13:26:00 01JUN19:13:29:00 10 
 3 01JUN19:13:00:00 01JUN19:13:30:00 30 
 5 01JUN19:13:20:00 01JUN19:13:30:00 22 
 5 01JUN19:13:20:00 01JUN19:13:30:00 22 
 3 01JUN19:13:18:00 01JUN19:13:34:00 17 
 2 01JUN19:13:25:00 01JUN19:13:47:00 26 
 4 01JUN19:13:41:00 01JUN19:13:58:00 23 
 4 01JUN19:13:41:00 01JUN19:13:58:00 23 
 3 01JUN19:13:49:00 01JUN19:13:55:00 16 
 2 01JUN19:13:48:00 01JUN19:14:00:00 16 
 2 01JUN19:13:48:00 01JUN19:14:21:00 33 
 3 01JUN19:14:32:00 01JUN19:14:34:00 6 
 3 01JUN19:13:39:00 01JUN19:14:58:00 84 
 2 01JUN19:14:22:00 01JUN19:14:50:00 30 
 2 01JUN19:14:33:00 01JUN19:14:50:00 17 
 2 01JUN19:14:33:00 01JUN19:14:50:00 17 
 3 01JUN19:13:51:00 01JUN19:15:05:00 81 
 3 01JUN19:14:19:00 01JUN19:15:09:00 62 
 3 01JUN19:14:52:00 01JUN19:15:09:00 22 
 3 01JUN19:15:27:00 01JUN19:15:31:00 14 
 3 01JUN19:15:32:00 01JUN19:15:35:00 7 
 3 01JUN19:15:30:00 01JUN19:15:46:00 18 
;run;
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 771 views
  • 0 likes
  • 2 in conversation