LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
Comments: To: Rodney Presley <rpa9@CDC.GOV>

It DEFINITELY must be Friday. Try: http://listserv.uga.edu/cgi-bin/wa?A2=ind9908b&L=sas-l&P=12494

Art -------- On Fri, 20 Jul 2007 08:45:53 -0400, Presley, Rodney (CDC/CCHP/NCBDDD) <rpa9@CDC.GOV> wrote:

>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. > >Rodney > > >/* 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. >*/ >%macro word_cnt(word); > %global wdcount; > %local x; > %let count=0; > %let x=0; > %do %while (&x>=0); > %let count=%eval(&count+1); > %let x=%scan(&word,&count,' '); > %end; > %let wdcount=%trim(%eval(&count-1)); >%mend word_cnt; > >/* sample use. > %word_cnt(&members) >*/ > > >Rodney J. Presley, PhD >Division of Hereditary Blood Disorders >Work Phone: 404-718-8630 >Main Number: 404-718-8600 >Fax: 404-718-8650 >Email: RPresley@cdc.gov > > >-----Original Message----- >From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of >vatodorov >Sent: Thursday, July 19, 2007 4:31 PM >To: SAS-L@LISTSERV.UGA.EDU >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 >observation? > >thanks.


Back to: Top of message | Previous page | Main SAS-L page