Date: Fri, 20 Jul 2007 13:07:11 -0400
Reply-To: Arthur Tabachneck <art297@NETSCAPE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Arthur Tabachneck <art297@NETSCAPE.NET>
Subject: Re: How can I count the number of words per line within a variable
It DEFINITELY must be Friday. Try:
On Fri, 20 Jul 2007 08:45:53 -0400, Presley, Rodney (CDC/CCHP/NCBDDD)
>Try this little macro. I got it many years ago from someone on the list
>or an Observations article. But since I no longer know where I got it I
>can't give proper credit to the originator. But I use it frequently.
>/* this macro counts the number of words in a
> macro variable and places that value in the
> global macro variable "WDCOUNT".
> The number of words is used
> to set do loop counters in other macros.
> Macro variables:
> WORD is the name of the macro variable
> which contains the list of words
> to be counted.
> WDCOUNT is the name of the macro variable
> which will contain the number of "words"
> in the macro variable WORD after the
> macro runs.
> %global wdcount;
> %local x;
> %let count=0;
> %let x=0;
> %do %while (&x>=0);
> %let count=%eval(&count+1);
> %let x=%scan(&word,&count,' ');
> %let wdcount=%trim(%eval(&count-1));
>/* sample use.
>Rodney J. Presley, PhD
>Division of Hereditary Blood Disorders
>Work Phone: 404-718-8630
>Main Number: 404-718-8600
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>Sent: Thursday, July 19, 2007 4:31 PM
>Subject: How can I count the number of words per line within a variable
>I have a variable, which is a name. However, some people have written
>only their first and last name, where as others have put first, last and
>middle name. And there are some who may have more than three names.
>Does anyone have an idea of how to count the number of names for every