SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
alice_s
Calcite | Level 5

I need to calculate the total hh stay length for patient. below data example is for one patient's record. It includes start date, restart date, discharge date for each episode in three columns, and I needs to get stay length for all episodes. In this example, there are 3 episodes. 15-02-25 to 15-03-13, 15-03-23 to 15-04-07, 15-04-10 to 15-05-11. I'm confused how to deal with the restart_dt and I am struggled to get the total length for each patients in my dataset. Thanks for help if anyone has any ideas. 

 

alice_s_4-1649794131807.png

 

 

 

 

 

8 REPLIES 8
ballardw
Super User

So do you have SAS date values? Any manipulation works much better with those.

 

If not you have to tell which of those values is the year, which the month and which the day of the month so we can help you create date values.

 

It might help us to show exactly what result you are expecting.

 

Ideally you would post data as data step code that we can run pasted into a code box opened on the forum with either the </> or "running man" icons that appear above the message window. Or at least copied text pasted into one of the boxes. But we can't write code from a picture and very few of us are going to retype stuff from a picture.

 

Since you did not include any other information how do we know which values are to be consider for these calculations? With the word you are using like "discharge" one would expect at least a patient identifier so that w have some idea of what is going on. Without that, kind of requires mind-reading skills.

 

From that picture I have a very hard time getting this connection at all: 15-04-10 to 15-05-11.

mkeintz
PROC Star

Please explain the logic you are using to extract the reported results from the sample input data.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
pink_poodle
Barite | Level 11

Where there is no re-start, you would just take an interval in days between two date values: intck(‘day’, start, discharge). Where there is a re-start, I suppose that would be their second visit, you would need to know what was their second discharge (“re-discharge”), then sum the two intervals calculated with the intck function: sum( intck(‘day’, start, discharge), intck(‘day’, re-start, re-discharge)).

alice_s
Calcite | Level 5
Yes, this is my thinking process to calculate the length. I am good with record without re-start, it is very straightfoward. However, the problem if I need to calculate the interval between re-start and re-discharge, the re-start date is usually not on the same row of re-discharge, so I could not use 'intck' directly. This is the point I am struggling with.
pink_poodle
Barite | Level 11
The missing discharge dates can be filled with the value of previous non-missing discharge date like this:
https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-with-the-previous-values/td-p/326...
alice_s
Calcite | Level 5
yes this is helpful, but sometime, they have two pair of re-start date and re-discharge date, such as 15-03-23 to 15-04-07, 15-04-10 to 15-05-11 in above image. I dont know how to pair them to have the re-start date right before the re-discharge date instead of mixing them up.
pink_poodle
Barite | Level 11

The columns would need to be arranged in a better way. First take distinct non-missing values from each column in ascending order into a separate table. Then, for each table, create column Month = month(date). Re-merge columns by month. Finish by filling in missing values with last available value from the SAS post I shared previously. The resulting table will be much easier to work with.

andreas_lds
Jade | Level 19

Instead of re-Arranging the data, you should go back some steps an investigate how the dataset you have now was created, maybe intercepting in the process at an earlier stage makes it easier to solve the task.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 8 replies
  • 1658 views
  • 3 likes
  • 5 in conversation