03-27-2014 05:38 PM
If I had a dataset that contains ids and lab results and I wanted to flag patients that had two consecutive lab results > 4.5 how do I go about it?
So I would want to have another field called flag and it would field in this example 111 4.6 and 111 4.7 and also 333 4.6 and 4.7.
Thanks so much!
03-27-2014 07:16 PM
if first.id then flag=.;
else flag = ((Result > 4.5) and (lag(result)>4.5));
Will assign a flag value of one for records where the current and previous records have result > 4.5. If you need to have the flag on both records then there's signficantly more code involved.
This does require the data to be sorted by ID. Personally I would be much happier to also see a date or time variable to ensure the order is correct.
03-28-2014 06:59 AM
Sorry but that conditional LAG is not going to work here.
03-28-2014 07:41 AM
To flag the "run" you can read the data twice.