LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (February 2006, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 24 Feb 2006 01:00:47 -0500
Reply-To:   Melinda L Cordero <CorderoM@GAO.GOV>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Melinda L Cordero <CorderoM@GAO.GOV>
Subject:   Re: SAS-L Digest - 23 Feb 2006 to 24 Feb 2006 (#2006-348) (out of office)
Content-Type:   text/plain; charset=US-ASCII

I will be out of the office (in training) Thursday 2/23/06 and Friday 2/24. I will check email and voicemail when possible. I will return to the office Monday, 2/27/06.

-M

>>> SAS-L 02/24/06 01:00 >>>

There is one message totalling 76 lines in this issue.

Topics of the day:

1. Number of tokens

----------------------------------------------------------------------

Date: Thu, 23 Mar 2006 23:28:12 -0500 From: "Paul M. Dorfman" <sashole@BELLSOUTH.NET> Subject: Re: Number of tokens

Gregory,

First, you need the right tool for the job. The COUNT() function counts the number of times a specific substring appears in a given string. You appear to have logically planned to find the number of intervening blanks (and then add a unity plus account for the string that can possibly be empty, which provisions I am failing to detect in your code), then the less generic, and hence supposedly more efficient, COUNTC() function will work just as well. However, both will fail if the string happens to contain consecutive spaces, which would be a serious omission on part of a serious SAS programmer who understandably strives to make code robust. The latter would require a nested COMPBL() function to ensure all blanks are loners, which will then necessitate nested sysfunc() functions, for as you well aware, DATA step functions cannot be nested within a single sysfunc(). In other words, neither COUNT(), nor COUNTC() looks like an awfully attractive candidate for the job.

What else SAS has to offer from the same bin? Why, COUNTW(), if course, which directly addresses your problem:

1 %put %sysfunc (countw (a bb ccc dddd)) ; 4

The number of functions available in SAS nowadays seems pretty overwhelming, but oftentimes seeing analogies with what you already know by having used for years makes [relatively] new function a tad easier to remember owing to the consistency maintained among their names (thanks, SAS). For example, I have a hard time failing to see analogies in the following juxtapositions:

index count indexC countC indexW countW

Kind regards ------------ Paul Dorfman Jax, FL ------------

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On > Behalf Of gkotler@YAHOO.COM > Sent: Thursday, February 23, 2006 3:41 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Number of tokens > > I want to count the number of tokens in the list : > > 1. > data _null_; > p=count("122 211 333"," "); > put p=; > run; > > OUTPUT: p=2 - the number of blanks in the string > > 2. > %put %sysfunc(count("122 211 333", " ")); > > OUTPUT : 0 ????? > > Why ? > > > Thank you, > Gregory >

------------------------------

End of SAS-L Digest - 23 Feb 2006 to 24 Feb 2006 (#2006-348) ************************************************************


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