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 (March 2010, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 11 Mar 2010 08:50:51 -0600
Reply-To:     Joe Matise <snoopy369@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Joe Matise <snoopy369@GMAIL.COM>
Subject:      Re: efficient way to write more than one string identified into
              another variable
Comments: To: D T <sasandstats@live.com>
In-Reply-To:  <BLU132-W1532ADF548EBF23E97DD75C8320@phx.gbl>
Content-Type: text/plain; charset=ISO-8859-1

Pretty sure there's a more elegant way to do it, but could you something like

do until not(prxmatch(reg1,comment); dairy = prxposn(reg1,1,comment); comment = [rest of comment]; end;

Not remembering off the top of my head how to do that second line, but I don't think it's hard, just too early in the morning.

-Joe

On Thu, Mar 11, 2010 at 8:34 AM, D T <sasandstats@live.com> wrote:

> I am using perl regular expressions in SAS to extract text from a > variable with a varying number of comments. > I would like to be able to write more than one string identified into > another variable. Can anyone suggest an > efficient way to do this? > > In my example a search string such as: > > prxparse('/(milk\b|cheese\b|yoghurt\b|cheddar\b|cream\b\scheese\b|cream\b)/i') > would search for all dairy, > and would have several hits for id 1 and 5. How do I get them most > efficiently into variable dairy? > > > Here is the example: > > data start; > length comment $50; > input id comment &; > cards; > 1 milk, cheese bacon > 2 oranges/yogurt > 3 cheddar meatballs > 4 bread > 5 yogurt cream cheese, cream > ; > > data end; > set start; > > retain reg1; > > if _N_=1 then do; > > reg1=prxparse('/(milk\b|cheese\b|yogurt\b|cheddar\b|cream\b\scheese\b|cream\b)/i'); > end; > > if prxmatch(reg1,comment) then do; > dairy=prxposn(reg1,1,comment); > end; > > run; > > data end should look like this: > > id dairy meats fruit grains > 1 milk, cheese bacon > 2 yoghurt oranges/ > 3 cheddar meatballs > 4 bread > 5 yoghurt cream cheese, cream > > Thanks! > > D.T. > _________________________________________________________________ > Hotmail: Free, trusted and rich email service. > http://clk.atdmt.com/GBL/go/201469228/direct/01/


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