Date: Thu, 11 Mar 2010 14:19:41 -0500
Reply-To: D T <sasandstats@LIVE.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: D T <sasandstats@LIVE.COM>
Subject: Re: efficient way -- prx & catx -- not solved yet
In-Reply-To: <b7a7fa631003110808t1c62b496r8855e9bc0c7abca3@mail.gmail.com>
Content-Type: text/plain; charset="Windows-1252"
Can anyone help out? catx seems to be a good idea, but I am still not able to get it working.
See just below for current code (not working correctly) and further down for original problem. I have incorporated two suggestions from Joe, but have not yet solved this.
Thanks for your help!
data end;
set start;
retain reg1;
length dairy $30 ;
start=1;
stop=length (comment);
if _N_=1 then do;
reg1=prxparse('/(milk\b|cheese\b|yogurt\b|cheddar\b|cream\b\scheese\b|cream\b)/i');
end;
call prxnext(reg1, start, stop, comment, position, length);
do while (position > 0);
Dairy= catx(' ',dairy,prxposn(reg1,1,comment));
replace=cats ("s$",dairy,"$$");
comment=prxchange(replace,1,comment);
if start > stop then position = 0;
else
call prxnext(reg1, start, stop, comment, position, length);
end;
Here is the problem:
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.
> Date: Thu, 11 Mar 2010 10:08:41 -0600
> From: snoopy369@GMAIL.COM
> Subject: Re: [SAS-L] efficient way to write more than one string identified into another variable
> To: SAS-L@LISTSERV.UGA.EDU
>
> Dairy= catx(' ',dairy,prxposn<stuff>);
>
> or something to that effect.
>
>
>
> -Joe
>
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/201469226/direct/01/ |