|
This post was updated on .
I work with hospital data at a public hospital and are currently struggling to make a macro to help me create an overview over the number of hospitalized patients at every hour (or minute) during the year based on admissions presented as cases with date-time variables for admittance and discharge.
I wish to get a set of new variables describing how many patient that are present at any given hour interval during the year. My solution this far has been to create a new variable for each hour intervall for each date of the year (24 x 365; "IF IN>=... AND OUT <=... xxx=1" lines). This does the trick, but it is quite time and line consuming process, and I'm quite sure the must be an easier way to do this using macros! Here is my exact syntax (that I have to repeat over 10 000 times): IF ((In <= (DATE.DMY(1,1,2015)+TIME.HMS(0.0)))) AND ((OUT >=( DATE.DMY(1,1,2015)+TIME.HMS(0.0)))) B20150101_00=1. I also been thinking that I'm looking at this all wrong and that there might be an even more clever solution to get what I want without creating all this variables? Ideally I want to be able to do this for every minute (or continusly). But I need to be able to group my patients by other grouping variables when describing the present populations. Here is a simple syntax creating some example data, just to get started. DATA LIST LIST / Id In Out. BEGIN DATA. 1 5 8 2 5 9 3 6 7 4 6 12 5 7 8 6 7 10 END DATA. LIST. Best regards Lars N. |
|
If you can save the file externally, LOOPs and XSAVE work nice to expand the data. This is presuming you don't need to expand the data to when people are not in the hospital.
**************************************. SET SEED 10. DATA LIST LIST / Id (F1.0). BEGIN DATA. 1 2 3 4 5 6 END DATA. DATASET NAME Orig. COMPUTE DateTimeIn = DATESUM(DATE.MDY(1,1,2015),RV.UNIFORM(0,100),"HOURS"). COMPUTE DateTimeOut = DATESUM(DateTimeIn,RV.UNIFORM(0,24),"HOURS"). FORMATS DateTimeIn DateTimeOut (DATETIME17). EXECUTE. FILE HANDLE save /NAME = "\\finnhudson\USERS_REDIRECT$\andrew.wheeler\Desktop". *Convert time to hours since a fixed point. COMPUTE #BeginPoint = DATE.MDY(1,1,2015). COMPUTE #B = DATEDIFF(DateTimeIn,#BeginPoint,"HOURS"). COMPUTE #E = DATEDIFF(DateTimeOut,#BeginPoint,"HOURS"). NUMERIC TimeHour (DATETIME17). LOOP #I = #B TO #E. COMPUTE TimeHour = DATESUM(#BeginPoint,#I,"HOURS"). XSAVE OUTFILE = "save\ExpandedData.sav". END LOOP. GET FILE = "save\ExpandedData.sav". DATASET NAME Expanded. **************************************. |
|
Thank's a lot. I understand the basics, and it seems like a fine nice solution - saving data externally is no problem. I will have to try to implement it on my real data and see if I get it to work as i want in action. Best regards Lars N. 2015-10-02 15:11 GMT+02:00 Andy W [via SPSSX Discussion] <[hidden email]>: If you can save the file externally, LOOPs and XSAVE work nice to expand the data. This is presuming you don't need to expand the data to when people are not in the hospital. |
|
Administrator
|
I would certainly run with a long file as Andrew has illustrated. Certainly a terrible mistake to create 365*24=8760 new variables. You can simply use AGGREGATE to create your counts from the long expanded file and use whatever grouping conditions of interest as BREAK variables.
Note on the XSAVE you can use /KEEP to retain only the variables you require rather than making copies of the likely many subject level variables. If you need to bring them in later use simply MATCH FILES to attach them to the expanded data.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
|
Thank's for the supplementary tips David. It took me some time to understand the syntax, but it has been realy usefull and as a bonus I have learned a lot of new syntax commands. I made i small adjustment to the syntax, so that instead of counting every hour interval a patient has been present it now only a counts if patients has been present at each whole hour. I did this by adding +1 to the "COMPUTE #B"-comand, (COMPUTE #B = DATEDIFF(DateTimeIn,#BeginPoint,"HOURS")+1.) Thanks for great tips and helps, this helps a lot. Best regards Lars N. 2015-10-05 7:12 GMT+02:00 David Marso [via SPSSX Discussion] <[hidden email]>: I would certainly run with a long file as Andrew has illustrated. Certainly a terrible mistake to create 365*24=8760 new variables. You can simply use AGGREGATE to create your counts from the long expanded file and use whatever grouping conditions of interest as BREAK variables. |
| Free forum by Nabble | Edit this page |
