03-25-2015 05:19 PM
Please bare with me, as I am very new to SAS/SQL. I took the online tutorial classes for SAS and dug deep in text books and youtube videos. I thought I had a good grasp on the basics and then my boss let me know that he'd like my first task to be done using SQL.
So, I'm still trying to wrap my mind around it all; is this done in conjunction with one another, how am I going to do this most effectively, etc.
So, here is my task. There's a LOT of data (observations).
Any help would be greatly appreciated. I just don't even know where to begin and is this even possible by just doing SQL, or do I switch off between traditional SAS steps and SQL?
03-25-2015 09:38 PM
First, figure out how to match which admission with a discharge, is there a visit ID for starters?
If so you can do a left join and your admissions without discharges will be clear.
Or you can check which visitID's are not in the discharge table.
Yes, this can all be done in SQL given what you've stated so far.
03-26-2015 02:14 PM
03-26-2015 03:15 PM
Get the latest admin date, if it is a SAS date variable ( and really should be) then the MAX when grouped by patient id and hospital
Do the same for the discharge date
Join those two. If the discharge date is missing OR less than admin they either 1) are still in the hospital or 2) the records aren't quite up to date. (hint: where admin_date > discharge_date)
Of course this will all be as of the date/time the data was extracted.
It may be advantageous to combine multiple admit sets into one and the same for discharge keeping the minimum amount of data.
As an aside about your comment of hospital codes instead of names: Rejoice! Codes can be kept for the same building (or other concept of continuity) where as Hospitals may change names for marketing or other purpose such as merger and you lose continuity. I deal with the reverse of this in School names without a code. Every year I have to a bunch of sleuthing about are new names actually renamed old schools a are missing previously listed schools actually closed or renamed or typos in data entry.
03-26-2015 04:12 PM
What kind or version/dialect of SQL he is wanting. It he is thinking all SQL is equal that is a failure from start. For instance with SAS datasets you are having 2 value logic (true/false). Within a RDBMS there is 3 values logic (true-false-uknown) the last better known as NULL.