/*** Tip 00380 ***/
Subject: Finding repeating characters

Is there a function or whatever to find characters that are repeated 5 or
more consecutive times such as 'AAAAA' through 'ZZZZZ' anywhere in a
character string. Example 'This is aaaaa character string' that I want to
find 'but this is not ooone'.

Solution #1 Author: Droogendyk, Harry Email: Harry.Droogendyk@CIBC._NOSPAM_.COM No function that I know of, but here's a chunk of code that finds 'em: data a; infile cards pad truncover; length string $100; input string 1-100 ; cards; This is aaaaa character string ssssstart of the string but this is not ooone here's one on the end of the stringgggg here's one on the end of the stringggg run; data _null_; length five $5 one $1 ; set a; a = addr(string); do _i = a to ( a+length(string)-5); five = peekc(_i); one = five; if five = repeat(one,4) then do; put string=; leave; end; end; run;
Solution #2 Author: Huang, Ya Email: yhuang@AMYLIN._NOSPAM_.COM Similar to Harry's solution, if you don't feel comfortable with peek() and addr(): data xx; input a $1-50; cards; This is aaaaa character string but this is not ooone ; data _null_; set xx; found='No'; do i=1 to length(a)-5; if substr(a,i,5)=repeat(substr(a,i,1),4) then found='Yes'; end; put a= found=; run; a=This is aaaaa character string found=Ye a=but this is not ooone found=No NOTE: There were 2 observations read from the data set WORK.XX.
Solution #3 Author: Fehd, Ronald J. Email: rjf2@CDC._NOSPAM_.GOV you'll be good at arrays when you finish this task! index(Text,string); will return colum where String occurs in Text so: String ='aaaaa'; HasA = index(Text,string); String ='bbbbb'; HasB = index(Text,string); array Strings (26) $ 5 _temporary_ ('aaaaa','bbbbb',...,'zzzzz'); array Has (26) 4; %*allocates Has1 Has2 ... Has; drop I; do I = 1 to dim(Strings);Has(I) = index(Text,String(I));end; Has* will have values in 0:length(Text)-5; to return boolean: index(Text,String(I)) ge 1
/*** end of tip 00380 ***/