If more than one sequence of repeated characters can occur in the same string (as in happygggg), it is useful to work with two separate counters (LEN vs. MAX_SEQ in the code below, using Reeza's variable names):
data want;
set have;
length max_seq_letter $20
max_char $1;
do i=2 to length(email);
len=1;
do while(char(email, i)=char(email, i-1));
len+1;
i+1;
end;
if len>max(max_seq, 1) then do;
max_seq=len;
max_char=char(email, i-1);
end;
end;
if max_seq then max_seq_letter=repeat(max_char, max_seq-1);
output;
label max_seq='Counts of Repeat'
max_seq_letter='Character Repeats';
drop i len max_char;
run;
... View more