|Date: ||Wed, 28 Jun 2006 16:40:52 +0200|
|Reply-To: ||magnusson tomas <tmagnusson@MEDISERVICE.CH>|
|Sender: ||"SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>|
|From: ||magnusson tomas <tmagnusson@MEDISERVICE.CH>|
|Subject: ||AW: regular expressions in SAS|
|Content-Type: ||text/plain; charset="iso-8859-1"|
For your specific case I would try something like
if find(lowcase(drag1),'twink')>0 then drag1=tranwrd(lowcase(drag1),'twink','whatever');
Von: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]Im Auftrag von
Beaulieu, Serge (DHW/SME)
Gesendet: Mittwoch, 28. Juni 2006 15:41
Betreff: 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
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 come here.
Any help greatly appreciated!