Date: Wed, 7 Dec 2005 10:24:13 -0500
Reply-To: ben.powell@CLA.CO.UK
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: ben.powell@CLA.CO.UK
Subject: Re: Wild card equivalent in SAS ?
Content-Type: text/plain; charset=ISO-8859-1
triple negative, bad idea.
On Wed, 7 Dec 2005 04:38:17 -0500, ben.powell@CLA.CO.UK wrote:
>Unusally for a DC post I think I understand this one...
>
>Which is not to say I can't believe there is not a simpler way to write:
>
>
>%let wildcard=sysfunc(dothewildthing);
>data a;
>set b;
>where c like("mening.&wildcard.W135");
>run;
>
>than:
>
>data a;
>set b;
>re = prxparse('/mening\.\w+\.W135/');
>if prxmatch(re, c);
>run;
>
>
>hmmm...
>
>
>On Tue, 6 Dec 2005 17:06:11 -0800, David L Cassell <davidlcassell@MSN.COM>
>wrote:
>
>>stringplayer_2@YAHOO.COM replied:
>>>You aren't exactly clear about what you need to accomplish.
>>>You speak of replacing TEXT in lines where 'mening.TEXT.W135'
>>>is true. Are you reading a flat file where and rewriting
>>>the flat file, updating records where the entire line
>>>follows the specified template?
>>>
>>>If so, and if you read the entire line as a single variable
>>>named LINE, then the scan function could be employed to
>>>identify records which need to be updated. This is quite
>>>easy, assuming a recent version of SAS, say V8.x and above.
>>>You can scan for the first word delimited by a '.' and
>>>scan for the last word delimited by a '.'. Having identified
>>>a line which needs to be replaced, you can rewrite the line
>>>concatenating 'mening.' and '.W135' with replacement text
>>>sandwiched in between.
>>>
>>> if scan(line,1,'.')='mening' AND
>>> scan(line,-1,'.')='W135' then
>>> line = 'mening.' || '<replacement text>' || '.W135';
>>>
>>>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() function
>>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; end;
>> end;
>> if prxmatch(re, VarToBeChecked);
>> run;
>>
>>
>>David
>>--
>>David L. Cassell
>>mathematical statistician
>>Design Pathways
>>3115 NW Norwood Pl.
>>Corvallis OR 97330
>>
>>_________________________________________________________________
>>Don’t just search. Find. Check out the new MSN Search!
>>http://search.msn.click-url.com/go/onm00200636ave/direct/01/
|