Does the patient have only one 0 disease value before the first 1 disease value or can there be multiple 0 values before the first 1?
Edit:
Here are two possible solutions depending on the data:
In the first one sort the data first by patientid and time, then create two formula columns and check should have the information you are interested in. There might be some edge cases this will miss (like the last row).
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(14),
Compress File When Saved(1),
New Column("PatientID",
Numeric,
"Nominal",
Format("Best", 12),
Set Values([1, 1, 1, 1, 2, 2, 1, 3, 3, 3, 3, 1, 1, 1]),
Set Display Width(62)
),
New Column("Status",
Numeric,
"Nominal",
Format("Best", 12),
Set Values([0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0]),
Set Display Width(50)
),
New Column("Time",
Numeric,
"Continuous",
Format("m.d.y h:m", 19),
Input Format("m.d.y h:m"),
Set Values(
[3660718210, 3660718260, 3660718320, 3660718380, 3660718440, 3660718500, 3660718560, 3660718620, 3660718680,
3660718740, 3660718800, 3660718860, 3660718920, 3660718920]
)
)
);
// Sort data table
dt << Sort(By(:PatientID, :Time), Replace Table, Order(Ascending, Ascending));
//add formula columns
dt << New Column("CumSumOfStatus",
Numeric,
"Continuous",
Format("Best", 12),
Formula(Col Cumulative Sum(:Status, :PatientID))
);
//add formula columns
dt << New Column("Check",
Numeric,
"Continuous",
Format("Best", 12),
Formula(
If(Row() == 1, :Status);
If(Lag(:CumSumOfStatus, -1) == 1 & Lag(:PatientID) == :PatientID,
1,
0
);
)
);
Second one is expecting that patientid has only one 0 status before first 1 status which allows you to just get minimum times for both statuses using summary:
//If only one 0 before 1
dt2 = New Table("Untitled",
Add Rows(11),
Compress File When Saved(1),
New Column("PatientID",
Numeric,
"Nominal",
Format("Best", 12),
Set Values([1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3]),
Set Display Width(62)
),
New Column("Status",
Numeric,
"Nominal",
Format("Best", 12),
Set Values([0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0]),
Set Display Width(50)
),
New Column("Time",
Numeric,
"Continuous",
Format("m.d.y h:m", 19),
Input Format("m.d.y h:m"),
Set Values(
[3660718380, 3660718560, 3660718860, 3660718920, 3660718920, 3660718440, 3660718500, 3660718620, 3660718680,
3660718740, 3660718800]
)
)
);
dt << Summary(Group(:PatientID), Min(:Time), Subgroup(:Status), Freq("None"), Weight("None"));
-Jarmo