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 (September 2010, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 10 Sep 2010 12:28:21 -0500
Reply-To:     Joe Matise <snoopy369@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Joe Matise <snoopy369@GMAIL.COM>
Subject:      Re: parsing text
Comments: To: Suzanne McCoy <Suzanne.McCoy@catalinamarketing.com>,
          "Miller, Jeremy T. (CDC/CCID/NCHHSTP)" <zyp9@cdc.gov>
In-Reply-To:  <4B7D94293459DE418D902EFAF874C4A707AA983F76@STPPEX.catmktg.com>
Content-Type: text/plain; charset=ISO-8859-1

As long as there aren't parens in the rest of the title scan should work fine. If there are parens in the rest of the title, then you could use the -1 modifier:

scan(descr,-1,'()')

which will grab the LAST match (first from right) and should work for your data. Of course this is subject to the standard 'you gave me one line of data so if things are not as presented unexpected things may happen'. :)

-Joe

On Fri, Sep 10, 2010 at 12:21 PM, Suzanne McCoy < Suzanne.McCoy@catalinamarketing.com> wrote:

> The scan will treat each as a delimiter and may not do what you think it > should. I suggest index for '(' then index for ')' and then pick off > everything between the spaces. > > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > Miller, Jeremy T. (CDC/OID/NCPDCID) > Sent: Friday, September 10, 2010 1:10 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: parsing text > > I need to pull out some text between two parens. I've solved the > problem, but was wondering if there was a better way besides > PRXPARSE...I just can't find the time to learn Perl reg exp. for this. > > > > My requirement is that I have to do this in SQL. > > > > I thought if I could SCAN backwards picking out the string between "(" > and ")", but I'm not grasping the modifiers correctly. > > > > I think I could also use a select case when LENGTHC = and use a regular > substring with constants, but I'd rather stick to a one liner. > > > > > > > > data a; > > length desc $35 ; > > do ID = 1 to 10; > > if id <= 5 then descr = "Neonatal Critical Care (Level III)" ; > > else descr = "Neonatal Critical Care(Level II/III)" ; > > output; > > end; > > run; > > > > proc sql ; > > select id, substr(descr,index(descr,"(")+1, (index(descr,")")) - > (index(descr,"(")+1 ) ) as level > > from a > > ; > > quit; >


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