IBM Support

Transformation commands with LAG() function ignore Split File structure of data

Question & Answer


Question

I have a data set where each case refers to a clinic visit by a patient. The patient is identified by Patient_ID and the date of the visit is stored in the date variable Visit_Date. Each patient may make multiple visits, so that a patient may be represented in multiple cases. I would like to compute a new variable which stores the number of days since the patient's previous visit. The file is sorted by Patient_ID and Visit_Date, with Patient_ID then designated as the Split File variable. The date of the previous visit for each case, Prev_Date, would be computed as lag(Visit_Date,1), provided that the preceding case had the same Patient_ID as the current case. The difference would then be computed as the current date minus the previous date and converted to days. Here are my syntax commands: SORT CASES BY Patient_ID Visit_Date (A). SPLIT FILE by Patient_ID . COMPUTE Prev_Date=lag(Visit_Date,1). FORMATS Prev_Date (DATE11). COMPUTE Days_Between_Visits=Datediff(Visit_Date,Prev_Date,"Days"). EXECUTE. I expected the first case for each Patient_ID to have system missing values for Prev_Date and Days_Between_Visits due to the designation of Patient_ID as a Split File variable. However, only the first case in the sorted file is missing on those two new variables. It seems that the LAG() function is pulling information from the previous case, regardless of whether the current and previous cases are in the same Split File group. Is the LAG() function ignoring the Split File structure of the data?

[{"Product":{"code":"SSLVMB","label":"IBM SPSS Statistics"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Component":"--","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"Not Applicable","Edition":"","Line of Business":{"code":"LOB76","label":"Data Platform"}}]

Log InLog in to view more of this document

This document has the abstract of a technical article that is available to authorized users once you have logged on. Please use Log in button above to access the full document. After log in, if you do not have the right authorization for this document, there will be instructions on what to do next.

Document Information

More support for:
IBM SPSS Statistics

Software version:
Not Applicable

Document number:
204611

Modified date:
16 April 2020

UID

swg21584422

Manage My Notification Subscriptions