| Date: | Tue, 23 Jul 1996 12:58:52 GMT |
| Reply-To: | Frank Schnekenburger <ay987@FreeNet.Carleton.CA> |
| Sender: | "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU> |
| From: | Frank Schnekenburger <ay987@FREENET.CARLETON.CA> |
| Organization: | The National Capital FreeNet |
| Subject: | Re: Counting String Accurances |
|---|
Richard Dickinson (R-Dickinson@TAMU.EDU) writes:
> 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":
>
> 8883yyd6wefindme9djhhw9n43findmel9jjsosuhehnd
> findmeohu3p9uhdfvpiuhq3rfguhargpuhqrgpih
> rqpeoituqoepitu-974oijwgoijvoijfindme88ehfhfi
>
> In the first record "findme" occurs twice, and in the second and third
> records "findme" occurs once.
>
Hello, I think this will do what you're looking
for:
%let findstr = "findme";
data test;
length c $ 50;
input c;
cards;
8883yyd6wefindme9djhhw9n43findmel9jjsosuhehnd
findmeohu3p9uhdfvpiuhq3rfguhargpuhqrgpih
nonehere
rqpeoituqoepitu-974oijwgoijvoijfindme88ehfhfi
;
proc print; run;
data test;
set test;
keep c count;
count = 0;
cc = c; /* working copy of string */
i = index(cc, &findstr);
do while (i > 0);
count + 1;
cc = substr(cc, i + 1);
i = index(cc, &findstr);
end;
run;
proc print; run;
Hope it helps.
Frank.
|