Thank you so much for your great posts. For both overlapping and non-overlapping substring within a string the little modified (p = find(s, x); and iterate n-1 times) code works, otherwise existing code start searching from the (p+w)-th position of the string:
data a;
s='AB bhdf AAAAAb fs ABC Nfm AAB ';
x='AA';
n=3;
w=length(x);

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