03-30-2015 03:10 PM
Hello Previously I had asked SAS Communities how to create a data set so that I had one line of data per day of an inpatient visit and Reeza kindly provided the code below: data want; set have; do date=admit_date to discharge_date; output; end; run; proc freq data=want; table have; run; What I would like to do now is the same sort of thing but for ED visits and I'd like a line of data per HOUR of the visit. So if the patient was in the ED from noon to 5:00 I'd like one line of data each for the hours of 12, 13, 14, 15, 16, and 17. Any assistance greatly appreciated.
03-30-2015 03:16 PM
Same idea but change your do loop to have a record for each hour, assuming you have date time variables that represent the date/time of the visit and using the fact that 60 seconds * 60 minutes = 3600 seconds/hour
do date_hour=admit_datetime to discharge_datetime by 3600;
Then proc freq on date_hour.
03-30-2015 05:17 PM
Sorry Reeza, I just checked some of the data and I'm not sure it's working as I expected. For instance, a chart with an admit date of 02Apr14:04:41:00 and a disposition date of 02Apr14:15:10:00 should have visits for hours 04 to 15 but only has from 04 to 14 in the database. Why would it not also include 15? It seems to be prevalent in the resulting dataset that the end hour is not included. Thanks.
03-30-2015 06:52 PM
You'll probably need to increment the disposition date for the loop
I don't have time to test it now, but you can try something like the following to change the end date.
Another option is to change the loop to a do while loop and use the intnx function to increment the time.
date=intnx('hour', date, 1);
03-30-2015 07:03 PM
And a second bit depending on how and where your create and compare the end value: MINUTES
If you increment the admit date/time of 02Apr14:04:41:00 by two hours (02Apr14:06:41:00) and compare to a disposition datetime of 02Apr14:06:10:00 then you might be terminating your loop early using
do while(date<disposition_date); because the date skips over the disposition data and the dependent statements (such as OUTPUT) are not executed for the 06:41:00 value.
You may need to get a comparison value for your base comparison admit date to drop minutes before looping. and I think you may want le instead of < .
03-31-2015 03:15 PM
Hi Okay, I've got it and it works as I wanted. I used the loop_end_dt version and then used that as the end date in my "data want" data set i.e. do date_hour=adm_date to loop_end_dt by 3600. Thanks to you both.