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 (February 2006, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 10 Feb 2006 17:13:43 +0000
Reply-To:   toby dunn <tobydunn@HOTMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   toby dunn <tobydunn@HOTMAIL.COM>
Subject:   Re: Numeric macro variable
Comments:   To: paul.dorfman@FCSO.COM
In-Reply-To:   <200602101659.k1AGTjIV031234@mailgw.cc.uga.edu>
Content-Type:   text/plain; format=flowed

Paul,

Countc isn't in v8 only v9. I tend to go with %eval( %sysfunc( countc( &str , ' ') ) + 1 ) . Always seems a little more straight forward and bullet proof to count the number of delimiters and add 1 to get the number of elements in a string.

Toby Dunn

From: "Dorfman, Paul" <paul.dorfman@FCSO.COM> Reply-To: "Dorfman, Paul" <paul.dorfman@FCSO.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Numeric macro variable Date: Fri, 10 Feb 2006 11:59:56 -0500

Ian,

Methinks now that we have COUNTC(), it is a tad simpler to use an expessions like

%sysfunc (countc (&str, 123456789))

which requires no length computations and cares not about any characters in the string other than the digits. I do not remember, though, if the function is available in V8. If not, those having not yet caught up with the newer version are best advised to use your formula.

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

On Fri, 10 Feb 2006 16:35:11 +0000, Ian Whitlock <iw1junk@COMCAST.NET> wrote:

>Hadassa Brunschwig <dassybr@hotmail.com> is passing a string >to a macro as (1,145,64,29) and transforming it to 1:145:64:29. >He wants to count the number of numbers in the string. > >Joep <jsteeman@BUSINESSDECISION.COM> suggested > >> %let str = 1:145:64:29 ; >> >> /* remove the numbers and count the length plus 1 */ >> %let num = %eval(%length(%sysfunc(compress(&str, '1234567890'))) + 1); >> >> %put num = &num; > >The formula does not handle the empty string and runs into trouble >with commas instead of colons. To handle these other cases one can use > > %let num = %eval((%length(%sysfunc(compress(%superq (str), '1234567890')))) > + (%length(%superq(str))>0)); > >I suspect that it would be better to pass the string as > > %str(1,145,64,29) > >and learn to handle the macro quoting funtions, but it depends on how much >manipulation of strings Hadassa's application really calls for and whether >one wants to enter this world. > >One curious result about %EVAL. I originally left out the parentheses around >the two terms to be added. Without these parentheses %EVAL could not add the >numbers correctly becasue EVAL was adding the two lengths and then comparing >the sum to 0. > >Ian Whitlock


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