I came across this posting that describes some pitfalls to SAS word count programs:
The post goes on to discuss possible Word count programs of which I think the nicest one is this simple macro:
%macro nwords(s);
(compress(&s) ne ' ') *
(length(left(compbl(&s)))-length(compress(&s))+1)
%mend nwords;
data _null_;
string = "dasj h 07y lk0 - ldsmv";
nwords = %nwords(string);
put nwords=;
run;
/*NWORDS=6*/