R-Dickinson@TAMU.EDU (Richard Dickinson) wrote:
>Any one have any ideas on how to easily achieve this? I want to count
>the number of occurances of a specific string in a record (for example,
>the string "findme":
>In the first record "findme" occurs twice, and in the second and third
>records "findme" occurs once.
Here's a possible solution, assuming that your "records" consist of a
single character variable named x:
data new: set old;
y=x; count=-1; drop y position;
do until (position=0);
One issue you haven't addressed is based on this problem:
How many occurrences of string 'fcf' occur in string 'fcfcf'?
My algorithm would report the answer as 2. If you don't want to
consider overlapping strings, or are sure they will never occur, you
can make the algorithm a little more efficient by editing line 5 of
the above program to the following:
Why 6? Because 'findme' has 6 characters.
"Mama's li'l baby loves Rhubarb-a-Rhubarb,
Bebop-a-Rebop Rhubarb pie!"