« SAS Program for Word Frequency Count | Main | 20 year old code »

SAS Word Count Program

I came across this posting that describes some pitfalls to SAS word count programs:

  1. does it avoid the 200 length limitation of character variables in a data step?
  2. does it avoid the do loop in macro code which may be very slow if called multiple times?
  3. 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*/

 

 

 

Posted on Monday, March 31, 2008 by Registered CommenterJared in | Comments1 Comment | References1 Reference

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (1)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    Response: just stopped by.
    Wasn't what I was looking for, but very fine website. Thank you.

Reader Comments (1)

....very....interesting....
Thanks for the comment ?
:P

November 24, 2008 | Registered CommenterJared

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>