As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Tips Talk:Counting Words in a List

From sasCommunity
Jump to: navigation, search

good tip! --Nancy 12:45, 18 June 2009 (UTC)

Good TIP, good instruction w/good examples; Looks complete. Charlie Shipp 15:24, 19 June 2009 (UTC)

Nice tip - ready to go! --Phil Miller (STATPROF) 17:26, 26 June 2009 (UTC)

Countw does not count words delimited by just blanks. See the example below. -- chang_y_chung 21:50, 14 January 2011 (UTC)

%macro countw(list=);
%mend countw;
%macro count(list=);
 %eval(%sysfunc(count(%cmpres(&list),%str( )))+1)
%mend count;
%let critters=wolverines/grizzles  moose;
%put countw=%countw(list=&critters);
%put count=%count(list=&critters);
%*-- on log

These two also behave differently (and incorrectly) when a null string is passed.

%let critters=;
%put countw=%countw(list=&critters);
%put count=%count(list=&critters);
%*-- on log
ERROR: The function COUNTW referenced ...
  • A tip should really convey just one idea. This one is not about word-counting per se, but rather about "borrowing" these functions for use in a macro. It is already on the long side; perhaps it should illustrate only COUNTW.--Howles 23:49, 26 January 2011 (UTC)
  • Perhaps there should be an article about the various word-counting functions, compared and contrasted. I would only favor that if the relevant documentation is weak, or hard to find. I think this wiki should try hard to avoid mission creep.--Howles 23:49, 26 January 2011 (UTC)