Date: Fri, 10 Feb 2006 11:59:56 -0500 "Dorfman, Paul" "SAS(r) Discussion" "Dorfman, Paul" Re: Numeric macro variable To: Ian Whitlock

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