Sunday, February 15, 2009

count word number using PRX

It is my way to count word number:

data _null_;
input;
line = prxchange('s/\b*(\w+)\b*/A/', -1, _infile_);
count = count(line, 'A');
put count=;
cards;
this is a test
;

++++++++++++++++++++++++++++++++++++++++++++++++

Apparently, the method above is outdated.
With SAS 9.2, we can count the words in a string easilier.
The functions countw do the trick.

No comments: