Date: Tue, 6 Dec 2005 21:51:43 -0800
Reply-To: Dale McLerran <stringplayer_2@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Dale McLerran <stringplayer_2@YAHOO.COM>
Subject: Re: Wild card equivalent in SAS ?
Content-Type: text/plain; charset=iso-8859-1
--- David L Cassell <davidlcassell@MSN.COM> wrote:
> stringplayer_2@YAHOO.COM replied:
> >David Cassell will undoubtedly offer up a Perl regular
> >expression (PRX??? function) which will accomplish the
> >identification and replacement all implemented in a single
> >call routine. It will be very elegant, but if you don't
> >know PRX functions, it will take you the better part of
> >a week to figure out just how the function works.
> I'm hurt. I thought that my PRX posts were as clear as water. :-)
> If our poster has 9.1, he can stuff the regex inside the PRXMATCH()
> and do this in one line of UNTESTED code:
> if prxmatch('/mening\.\w+\.W135/', VarToBeChecked);
> Now isn't that simple? The regex inside the forward slashes says:
> mening the letters 'mening'
> \. a real period
> \w+ one or more 'word' characters: A-Z, a-z, 0-9, or _
> \. another real period
> W135 the sequence 'W135'
> I personally prefer some error checking. The below code works as
> long as
> you have
> SAS 9:
> data newstuff;
> retain re;
> set oldstuff;
> if _n_=1 then do;
> re = prxparse('/mening\.\w+\.W135/');
> if missing(re) then do; putlog 'ERROR: evil regex loose!'; stop;
> if prxmatch(re, VarToBeChecked);
I tossed David a lazy fastball with no movement on the
pitch and he belted it out of the park. But let's see what
he can do with a curve ball.
Suppose that the text between 'mening.' and '.W135' contains
characters other that a-z, A-Z, 0-9, and _. The original
poster did not indicate that TEXT was just digits and/or
letters of the alphabet. Suppose that TEXT contains some
parentheses or commas or periods. The w+ will not match
those characters, so we would miss lines like
Is there a simple wild card structure which would match
all characters that appeared between 'mening.' and '.W135'?
Fred Hutchinson Cancer Research Center
Ph: (206) 667-2926
Fax: (206) 667-5977
Yahoo! DSL – Something to write home about.
Just $16.99/mo. or less.