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 (April 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 21 Apr 2004 21:41:54 +0100
Reply-To:     peter.crawford@BLUEYONDER.CO.UK
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Peter Crawford2 <peter.crawford@BLUEYONDER.CO.UK>
Subject:      Re: search string
Comments: To: "Rak, Randy" <>
Content-Type: text/plain; charset="utf-8"

very good you should share it


-----Original Message----- From: Rak, Randy [] Sent: Wed 21/04/2004 21:23 To: Cc: Subject: RE: Re: search string

P., your magic trick can be further succintified. R.

--- begin code --- data; infile cards col=col; input @'+' @@; col=col-1; put col= _infile_; cards; --+--+--+ +--+--+-- --------- +++++++++ ; run; --- end code ---

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Peter Crawford2 Sent: Wednesday, April 21, 2004 1:35 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: search string

here's a method using just infile and input The magic is in the infile option column= along with input @'string' Their are worth reading up ..... data _null_; infile cards column=col; do until (0); input @'+' @; pos=col-1 ; put pos= _infile_; end; cards; ---+--++--+ --+--+--+-- ----------- ; run; pos=12 ---+--++--+ pos=15 ---+--++--+ pos=16 ---+--++--+ pos=19 ---+--++--+ pos=11 --+--+--+-- pos=14 --+--+--+-- pos=17 --+--+--+--

Peter Crawford

On Tue, 20 Apr 2004 09:57:58 -0400, SAS Bigot <sas_bigot@ML1.NET> wrote:

>Here's a quick solution that uses the INDEX function. I prefer it over >a character by character search. You can probably find a way to make it

>even more efficient, but it's pretty quick as-is. > >data _null_; > length pos $33; > input str : $11.; > substr = str; > acc = 0; > do until (0); > tpos = index(substr,'+'); > if tpos = 0 then leave; > acc + tpos; > substr = substr(substr,tpos+1); > pos = trim(pos) || put(acc, 3.); > end; > put str= pos=; > cards; > ---+--++--+ > --+--+--+-- > ----------- > ; >run; > > > >----- Original message ----- >From: "Fehd, Ronald J. (PHPPO)" <rjf2@CDC.GOV> >To: SAS-L@LISTSERV.UGA.EDU >Date: Wed, 14 Apr 2004 16:11:13 -0400 >Subject: Re: search string > >> From: M M [mailto:laihere@YAHOO.COM] >> Hi group, I need some help on finding the positions of >> a certain string. Suppose for variable X, I have a >> value '---+---+-+'. I want to find the positions of >> string '+' (that is 4,8,10). It is easy to use index function to find

>> the first '+'. I guess there is no functions for finding other >> occurrences of '+'. I tried Do WHILE loop and I wasn't successful. >> Any suggestions would be greatly appreciated. > >your loop has to have some repetition beyond the first occurence: > >%Let LengthLine = 10; > >DATA Pluses; >length Line $ &LengthLine.; > >array PlusAt (&length(Line.) 4;%*integers for boolean; > >do Position = 1 to dim(PlusAt); >PlusAt(Position) = substr(Line,I,1) = '+'; >if PlusAt(Position) then output; >end; > >you didn't specify how you wanted >to contain the values of the positions. >this is an array of zeros and ones >Position contains the various occurrences >if any. > >otherwise if you want to use index >you'll need to find the first occurence >and then substring from Position+1 >and index again > >Position = index(Line,'+'); >if Position then do until not Position; >if Position lt length(Line); >Line = substr(Line,Position+1); >end; > >Ron Fehd the macro maven CDC Atlanta GA USA > >--> cheerful provider of UNTESTED SAS code from the Clue?Gee!Wrx <-- > >"Nothing is particularly hard >if you divide it into small jobs." >- Henry Ford, Industrialist >... repetitiously, > judiciously > deliberately > >-- > - I mean, what is it about a decent email >service?

_ ________________________________________________________________________________ The contents of this email, and any documents, files or previous email messages attached to it, are intended for the named recipient(s) only and may contain information that is privileged and/or confidential. Nothing in this email is intended to constitute a waiver of any privilege or the confidentiality of this message. If you have received this email in error, please notify me immediately by reply email (or call 210/949-8200) and destroy this message and attachments without disclosing, copying, distributing or using any of the information contained in or attached to this transmission.

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