Wordcount using rxparse
Counting words in a string using SAS regular expression functions
data _null_;
retain rx;
infile cards eof=eof;
input @1 string $char30.;
if _n_ = 1 then
do;
rx = rxparse('" "* ((~" "+ " "+) #1)*');
put @1 'Words'
@7 'String';
end;
call rxsubstr(rx, string || ' ', pos, len, score);
put @1 score 5.0-r
@7 string $char30.;
return;
EOF:
put 'end of data';
call rxfree(rx);
cards4;
123456789012345678901234567890
String
oneword
oneword
two words
three words here
big gaps a b c d
a*b*c=d
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;;;;

0 Comments:
Post a Comment
<< Home