In reply to Moshiur Rahman.

Hi Moshiur, you are absolutely correct, great catch! I think only "from left to right" non-overlapping code modification is needed. It can be as simple as replacing initial p=0 with p=1-w:

data a;
s='AB bhdf +BA s Ab fs ABC Nfm AB ';
x='AB';
n=3;
w=length(x);

/* from left to right */
p = 1-w;
do i=1 to n until(p=0);
p = find(s, x, p+w);
end;
put p=;
run;

Do you agree?