Date: Fri, 10 Feb 2006 11:59:56 -0500
Reply-To: "Dorfman, Paul" <paul.dorfman@FCSO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Dorfman, Paul" <paul.dorfman@FCSO.COM>
Subject: Re: Numeric macro variable
Methinks now that we have COUNTC(), it is a tad simpler to use an
%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.
On Fri, 10 Feb 2006 16:35:11 +0000, Ian Whitlock <iw1junk@COMCAST.NET>
>Hadassa Brunschwig <firstname.lastname@example.org> 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 = #
>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
> + (%length(%superq(str))>0));
>I suspect that it would be better to pass the string as
>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
>the two terms to be added. Without these parentheses %EVAL could not add
>numbers correctly becasue EVAL was adding the two lengths and then
>the sum to 0.