[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: Search a character value for a character' 2nd or higher order
From:       Paul Dorfman <paul_dorfman () HOTMAIL ! COM>
Date:       2003-08-29 22:01:03
[Download RAW message or body]

Howard,

Of course a function cannot be expected to return an array of values, but as
far as this issue goes, it does not appear to be necessary. A function like

index (source, number, excerpt)

could be easily implemented in the underlying software, and a call

index (str, n, '!')

would return the position of the Nth exclamation sign and zero if there are
less than N excerpts in the source. A number of functions [scan(),
ordinal()] are already designed like that. If it is needed to returned all
the positions, the function can be called in a loop, as usual.
Unfortunately, the macro-simulated "function" I offered yesterday,

  %macro rfind (source, number, excerpt) ;
     %local j x ;
     %do j = 1 %to &number ;
        %let x = &x+indexC(substr(&source,&x+1),&excerpt) ;
     %end ;
     &x
  %mend ;

cannot be called in a loop supplying increasing NUMBER, but the call

x = %rfind (s, 3, '!') ;

should still impart the idea. If it were desinged in the SAS guts, the
limitation would be off for all three arguments.
Kind regards,
=================
Paul M. Dorfman
Jacksonville, FL
=================


>From: Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
>Reply-To: Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Re: Search a character value for a character' 2nd or higher order
>             of occurrence?
>Date: Fri, 29 Aug 2003 17:04:07 -0400
>
>Just a comment, for what it's worth. This functionality could not be
>implemented as a function, because functions always return single values
>and SAS does not have a vector or list data type.
>
>On Thu, 28 Aug 2003 09:17:13 -0700, Laurie <laurieli_hua@YAHOO.COM> wrote:
>
> >Hi there,
> >
> >Is there a single function in SAS to get the multiple positions of one
> >single character in one character value?
> >
> >For example, from the source character value: adsf!12s!sf34!34sf, I
> >would want to get the 3 positions of the character "!", which are 5,
> >9, 14 in this case.
> >
> >I know the function INDEX() can get the first position of the
> >character "!", is there another function in SAS to get the second and
> >third positions of the character "!" directly?
> >
> >Thank you very much for any suggestion and advice in advance! Looking
> >forward to your help here.
> >
> >Sincerely,
> >Laurie

_________________________________________________________________
Enter for your chance to IM with Bon Jovi, Seal, Bow Wow, or Mary J Blige
using MSN Messenger http://entertainment.msn.com/imastar

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic