Keeping sequential values of a counter:
data want;
set have;
by notsorted pat fl;
retain count ;
if first.pat then count=.;
if first.fl and fl='y' then count+1;
if fl='y' then New=count;
drop count;
run;
IF your data does not have all of the PAT values together you won't like the result.
At which point, good luck sorting your data to correct order unless there are a lot of other variables involved to manage such.
You may want to consider setting numeric flag values of 1 instead of character 'y'.
If you most common use is "if variable ='y' then <do something> you can simplify code to : if variable then <do>. SAS treats 1 as "true" in comparisons. To get number of "yes" you can just sum the flag values in any number of procedures which may be easier then counting 'y'.
... View more