|
Dunn, Toby wrote:
> George,
>
> If your anything like myself you hate writing abunch of code for
> simple problems.
> Try the following:
>
> data _null_;
> a = "ABCcccABCdddABCfff";
> n = (length(a) - length(compress(a,'ABC'))) / 3;
> put n=;
> run;
>
> Short and too the point and gets the right answer.
In only extremely limited situations...
6 data null;
7 a = "CBA BACH";
8 n = (length(a) - length(compress(a,'ABC'))) / 3;
9 put n=;
10 run;
n=2
Oops! Tranwrd() is better
Here is a real goofy way, using macro. Not for production use.
%macro increment (mvar);
%let &mvar = %eval(&&&mvar + 1);
%mend;
data _null_;
string = "CBA BACH ABC foo ABC";
excerpt = 'ABC';
length s $200;
call symput ('x','0');
s = quote(tranwrd (string, excerpt, '%increment(x)'));
put s=;
s = resolve (s);
put s=;
n = symget('x');
put n=;
run;
--
Richard A. DeVenezia
http://www.devenezia.com/
|