SAS Word Count Program
I came across this posting that describes some pitfalls to SAS word count programs:
- does it avoid the 200 length limitation of character variables in a data step?
- does it avoid the do loop in macro code which may be very slow if called multiple times?
- does it allow one **and more** spaces as simultaneously valid delimiters?
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*/

Reader Comments