This is the follow up of another post I made before.
Turns out that, when creating that "counter" variable I want to include a condition so if a variable called "outcome" takes value "out of time", the counter is 0, but it shouldnt reset the count for that Id on that date.
This is my code as it is now:
DATA want;
SET have;
BY ID date time;
RETAIN attempt;
IF first.Date then RealAttempts = 1;
ELSE RealAttempts = min(3,RealAttempts+1);
IF Outcome ="Out Of Time" then RealAttempts=0;
run;
And this is how it should look:
data have;
infile datalines dsd delimiter=',';
input date :ddmmyy10. ID time :time8. Outcome :$40. Attempt ;
format date ddmmyy10.;
format time time8.;
datalines;
05/11/2020,1000,8:15:23,"Answered",1,
05/11/2020,1000,8:20:10,"Out Of Time",0
05/11/2020,1000,8:21:10,"Answered",2
05/11/2020,1000,9:05:15,"Out Of Time",0
;
But this is how it looks (on 3rd row it resets to 1 instead of 2)
data have;
infile datalines dsd delimiter=',';
input date :ddmmyy10. ID time :time8. Outcome :$40. Attempt ;
format date ddmmyy10.;
format time time8.;
datalines;
05/11/2020,1000,8:15:23,"Answered",1,
05/11/2020,1000,8:20:10,"Out Of Time",0
05/11/2020,1000,8:21:10,"Answered",1
05/11/2020,1000,9:05:15,"Out Of Time",0
;
Any idea?