Extracting only 3 consecutive Y values


Hi, my question is how to pick only consecutive 3 “Y” observations using SAS.

data s;
input id$ flag$ date;
A Y 12/04/1990
A Y 13/05/1989
A N 14/05/1989
A Y 21/05/1990
A N 23/06/1990
B N 12/04/1990
B Y 13/06/1989 } Y
B Y 14/09/1989 } Y
B Y 21/10/1990 } Y
B Y 23/01/1990
C N 12/02/1990
C Y 13/05/1989
C Y 14/11/1989
C Y 21/01/1990
C N 23/04/1990

i want only the observations which is marked with parentheses, which is three consecutive Y values im done with few steps but stuck at last step, help the needful

data ss;
set s;

the above program gives me the answer if i write a code like " If flag=“Y” and flagdown=“Y” ;" but ill get all the values with A B C, but i want pick only consecutive 3 observations with B…
help the needful…

Thanks & Regards;