This may get you started. Note use of the code box opened with the forum's {I} icon for code and a data step for example data.
data have;
input ID delay ;
datalines;
1 1
1 2
1 3
1 4
1 3
1 4
1 0
1 1
1 2
1 3
1 4
1 0
1 1
1 2
1 3
1 4
1 1
1 2
1 3
1 4
1 0
1 1
2 0
2 0
2 1
;
run;
data want;
set have;
by notsorted id;
retain count first4 .;
if first.id then do;
count=0;
first4=0;
end;
if delay=4 then do;
if first4=0 then do;
count=.;
first4=1;
end;
else count+1;
end;
else count=coalesce(count,0);
drop first4;
run;
I don't see anything that demonstrates what you meant by the greater than 13 though. So I'm not sure what that does.