In reply to muthia kachirayan.

Yes, your idea does work fast.
I like it for it simplicity and because it just do a one scan of the data file, which could be sometimes very very big, these days.
With a little help from SAS macros, your code could be like this

%macro gnTest(pattern);
if digit=%substr(&pattern,1,1) then count=1;
%do i=2 %to %length(&pattern);
else if count=%eval(&i-1) and digit=%substr(&pattern,&i,1) then count=&i;
%end;
else count= 0;
%mend;

%macro doIt(pattern);
data result(keep=pos freq);
retain count 0;
set have end=last;
%gnTest(&pattern);
if count = %length(&pattern) then do;
pos= _N_-%length(&pattern)+1;
freq + 1;
output;
end;
run;
proc sql noprint;
select min(pos), max(freq) into:start, :freq from result;
quit;
%put Pattern=&pattern Start=%cmpres(&Start) Freq=%cmpres(&freq);
%mend;

%doIt(12345);
%doIt(654321);