|Date: ||Wed, 28 Jun 2006 08:19:19 -0600|
|Reply-To: ||Alan Churchill <SASL001@SAVIAN.NET>|
|Sender: ||"SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>|
|From: ||Alan Churchill <SASL001@SAVIAN.NET>|
|Subject: ||Re: regular expressions in SAS|
|Content-Type: ||text/plain; charset="US-ASCII"|
Quick and dirty but should get you going in the right direction:
89 data test ;
90 input var &:$200. ;
91 newvar = prxchange("s/\w*twink\w*/whatever/i",-1,var) ;
92 put newvar= ;
93 cards ;
newvar=hey everyone, here is whatever
newvar=there is a whatever in my coffee
newvar=whatever, whatever little star
newvar=it is a teeny whatever in yer eye
\w* Match any alpha, can occur 0 or more times
twink Match the word twink
/whatever/ Replacement string
i Ignore case
Savian "Bridging SAS and Microsoft Technologies"
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Beaulieu, Serge (DHW/SME)
Sent: Wednesday, June 28, 2006 7:41 AM
Subject: regular expressions in SAS
I am a relative newbi to SAS (about 2 months of experience so far) and I
have encountered a situation where it looks like I may need to use regular
expressions and never having used this before - I am looking for advice.
Essentially, I had a csv file which has been successfully imported to sas. I
was going to try to fix the data before importing it but have since
abandoned that idea.
The data in the sas table that I wish to edit is in a column called 'drag1'
of this sas table called 'avenue'. In the drag column - which is formatted
as Character $75 - I need to find instances of particular text strings and
replace the entire field entry with something else dependent on the string
that was found.
For example I want to find every derivation of 'twinkle' or 'twi nky',
'^twinkles' or 'Btwinkl' and replace it with 'whatever'
I thought of using something like:
if drag1 eq 'twinkle'
or drag1 eq 'twinky'
or drag1 eq 'twinkles'
(insert lots of combinations here)
then do drag1 = 'whatever';end;
But even finding all of the combinations could take forever.
Essentially ... I want to find any occurance -like- ?twink? and replace the
entire string with 'whatever'.
I have also read something in a command called 'proc sql ... like'
'%twink%'. This seems like it might be close but am not sure how to imbed
that into the above which I have tested and works but only on those exact
values and I want to broaden the scope.
I posted this to the sas ods base reporting forum and someone suggested I
Any help greatly appreciated!