I am trying to get an SPSS script polished so that I can use it month to month and year to year, without having to get into it all that often to modify it. If you look at the picture above you will see the following variables:
SSN PatientID AdmitDate DischDate (I am trying to calculate the lapsed days in yellow).
I am trying to figure out days between readmissions. Each row represents a new admission and discharge date, so I have several duplicate SSNs in column A. The PatientIDs in column B are random initial numbers ending in a sequential number 001, 002, 003, for the same patient representing their admissions to the hospital. What I would like to do is ignore the initial admit day completely as I am only interested in time between discharge and their next admittance. This crosses over rows though, so I need to only allow this if either the SSNs are equal or the PatientIDs are in a sequential manner.
The way that I chose to do this was with CASESTOVARS (see below). It broke out all of my variables aside from SSN into four variables. So, I have the following variables:
SSN PatientId.1 PatientId.2 ... DischDate.4
The problem with my script arises because for this run the maximum number of sequential admissions and discharges for one person is four. However, in my program when I compute diff1 - diff5 in the program below (I wrote the program this way because there are times when the admissions and discharges per person is more than four) it only returns diff1 diff2 and diff3, because there are no AdmitDate.5 in this program. The reason this is a problem is because all of the other variables in the CASESTOVARS has four instances (PatientId.1 PatientId.2 ... DischDate.4). This causes an error in the program:
>Error # 4285 in column 26. Text: Admit_Date.5
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
After I run this first portion of the script I have to go into variable view and create variable diff4 or the second part of the program will not run.
Question 1: Aside from compute, is there a way to generate a variable that does not compute anything? All I need is a variable titled diff4 in this case, but since there are no cases of AdmitDate5, it shows an error for the creation process using compute.
Question 2: Is this the best way to run this? Would a lag or lead be easier to use?
Sorry about being so long winded, it has been over 20 years since I have messed with SPSS.
Here is my script:
get file = "xxx1".
sort cases by SSN(a) PatientId(a) Admit_Date(a) Disch_Date(a).
casestovars / id = SSN.
compute diff1 = datediff(Admit_Date.2, Disch_Date.1, "days").
compute diff2 = datediff(Admit_Date.3, Disch_Date.2, "days").
compute diff3 = datediff(Admit_Date.4, Disch_Date.3, "days").
compute diff4 = datediff(Admit_Date.5, Disch_Date.4, "days").
compute diff5 = datediff(Admit_Date.6, Disch_Date.5, "days").
save outfile = "\\xxx2".
get file = "\\xxx2".
/MAKE PatientId FROM PatientId.1 PatientId.2 PatientId.3 PatientId.4
/MAKE Admit_Date FROM Admit_Date.1 Admit_Date.2 Admit_Date.3 Admit_Date.4
/MAKE Disch_date FROM Disch_Date.1 Disch_Date.2 Disch_Date.3 Disch_Date.4
/MAKE Legal_Status FROM Legal_Status.1 Legal_Status.2 Legal_Status.3 Legal_Status.4
/MAKE Disch_Reason FROM Disch_Reason.1 Disch_Reason.2 Disch_Reason.3 Disch_Reason.4
/MAKE Lapsed_Days FROM diff1 diff2 diff3 diff4
SELECT IF NOT (SYSMIS(Admit_Date)).
formats Lapsed_Days (f4.0).
ADD FILES File * /keep SSN Index1 Disch_Reason Legal_Status Lapsed_Days.
save outfile = "\\xxx3".
Judging from the table you showed, I wonder if this will give you what you want?
SORT CASES BY SSN(A) AdmitDate(D).
IF SSN EQ LAG(SSN) Lapsed_Days = DATEDIFF(LAG(AdmitDate),DischargeDate,'days').
RECODE Lapsed_Days (MISSING=998).
SORT CASES BY SSN(A) AdmitDate(A).
MISSING VALUES Lapsed_Days (998). /* I assume this should be treated as missing.
p.s. - If you had provided that sample of your data as text rather than an image, people could have easily read it in to SPSS and played around a little and verified that things were working as intended.
"When all else fails, RTFM."
NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
|Free forum by Nabble||Edit this page|