How do I get the lag/lead function to work on the first case number per patient in my database?
I have a database of 1k+ variables and 800k rows. Each row is an intervention on a segment of a vessel, one patient may have several rows = many interventions on different vesselsegment but all within the same hospitalization. There are 4 vessels and I when I restructure the database I get 4 cases for each row=intervention. I have tried to post the data below:
data list list /id_nr (f6) segment_id_nr (f6) date (date9) C_RCA (f6) C_LM (f6) C_LAD (f6) C_LCx (f6) VESSEL(a3) max_stenos (f6) Culprit_PCI (f6) Procedure_type (f6).
BEGIN DATA
1, 5, 12-Jun-06, 1.00, .00, .00, .00, RCA, 3.00, 1.00, 2.00
1, 5, 12-Jun-06, 1.00, .00, .00, .00, LM, 1.00, ,
1, 5, 12-Jun-06, 1.00, .00, .00, .00, LAD, 4.00, ,
1, 5, 12-Jun-06, 1.00, .00, .00, .00, LCX, 1.00, ,
1, 5, 12-Jun-06, 1.00, .00, .00, .00, RCA, 3.00, 1.00, 2.00
1, 5, 12-Jun-06, 1.00, .00, .00, .00, LM, 1.00, ,
1, 5, 12-Jun-06, 1.00, .00, .00, .00, LAD, 4.00, ,
1, 5, 12-Jun-06, 1.00, .00, .00, .00, LCX, 1.00, ,
1, 5, 12-Jun-06, .00, .00, 1.00, .00, RCA, 3.00, ,
1, 5, 12-Jun-06, .00, .00, 1.00, .00, LM, 1.00, ,
1, 5, 12-Jun-06, .00, .00, 1.00, .00, LAD, 4.00, 1.00, 2.00
1, 5, 12-Jun-06, .00, .00, 1.00, .00, LCX, 1.00, ,
END DATA.
dataset name OrigData.
It should look something like this: enter image description here
What I want is to combine all data from the last two variables to be contained within the first 4 rows and later remove remaining rows so that I have 4 rows per hospitalization, each row corresponding to intervention in that row see data below that i have copy pasted in excel:
data list list /id_nr (f6) segment_id_nr (f6) date (date9) C_RCA (f6) C_LM (f6) C_LAD (f6) C_LCx (f6) VESSEL(a3) max_stenos (f6) Culprit_PCI (f6) Procedure_type (f6) Culprit_PCI2 (f6) Procedure_type2 (f6).
BEGIN DATA
1, 5, 12-Jun-06, 1.00, .00, .00, .00, RCA, 3.00, 1.00, 2.00,1.00, 2.00
1, 5, 12-Jun-06, 1.00, .00, .00, .00, LM, 1.00, , , ,
1, 5, 12-Jun-06, 1.00, .00, .00, .00, LAD, 4.00, , ,1.00, 2.00
1, 5, 12-Jun-06, 1.00, .00, .00, .00, LCX, 1.00, , , ,
END DATA.
dataset name OrigData.
I have tried with the lag/lead function but i cant get it to work
I have the following code:
compute seq = $casenum.
execute.
SORT CASES BY seq.
CREATE PCI_other_segmentvessel = LAG(Culprit_PCI,4).
CREATE proceduret_type2 = LEAD(procedure_type).
Execute.
Is this possible to do? Is it perhaps a lag
IF sid= lag(sid) and Vessel=lag(Vessel) PCI2 = lag(Culprit_PCI,4).
Execute.
None of these works properly. Could you point me to the right direction? I dont know if data will work but if copy pasted into excel it works.
Kind regards