| Date: | Wed, 16 May 2001 02:38:20 GMT |
| Reply-To: | Mike Melia <73611.3612@COMPUSERVE.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Mike Melia <73611.3612@COMPUSERVE.COM> |
| Organization: | RoadRunner - Cox |
| Subject: | Re: macro: count elements |
| Content-Type: | text/plain; charset=us-ascii |
Paul:
the code you provided is very slick indeed, However, there are few
problems with it. First, leading blanks generate an extra word. There
for an additional LEFT must be added. Second, this code only work in
all cases at v8 or above. Prior to V8, many if not all functions were
limited to 200 chars. At v6.09, it might return the correct number of
words but a warning message is generated regarding strings exceeding
200 chars is generated.
The following modifies your code and wraps it in macro. tthis macro
WILL return incorrect results of % and & are in the source string.
But a quoted version can be created if need be.
As previously noted, you will get warning messages under v6 if the
string exceeds 200 chars.
%MACRO WORDS(W);
%local x c b;
%if %quote(&w) eq %then %do;
%let x=0;
%goto mexit;
%end;
%LET c = %sysfunc(length(%sysfunc(compbl(&w))));
%let b = %sysfunc(length(%sysfunc(compress(&w))));
%let x =%eval(&c-&b+1);
%mexit:
&X
%mend words;
Mike Melia
paul_dorfman@HOTMAIL.COM (Paul Dorfman) wrote:
>Charles,
>
>A rather maladroit macro expression
>
>%eval(%sysfunc(length(%sysfunc(compbl (1&a))))-
> %sysfunc(length(%sysfunc(compress(1&a))))+
> %eval(%length(&a)>0))
>
>
>returns the desired quantity. The last, boolean, expression, causes it to
>return 0 if the &A resolves to null.
>
>Kind regards,
>========================
>Paul M. Dorfman
>Jacksonville, Fl
>========================
>
>>From: Charles Brokmann <cab@AIMSCO.COM>
>>Sas-Lers:
>>
>>I have a macro variable (parameterarray) whose value is equal to the
>>space-delimited list:
>> SEC_UPPER_CONTROL_LIMIT LOWER_CONTROL_LIMIT SEC_LOWER_CONTROL_LIMIT
>>UPPER_CONTROL_LIMIT
>>
>>Could anyone please recommend to me how I might be able to get a count
>>of the number of items in the value of this variable?
>>
>>Win2000Pro, V8.2.
>>
>>Thanks,
>>Charles
>
>_________________________________________________________________
>Get your FREE download of MSN Explorer at http://explorer.msn.com
|