Date: Tue, 6 Dec 2005 17:06:11 -0800
Reply-To: David L Cassell <davidlcassell@MSN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: David L Cassell <davidlcassell@MSN.COM>
Subject: Re: Wild card equivalent in SAS ?
Content-Type: text/plain; format=flowed
>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
if _n_=1 then do;
re = prxparse('/mening\.\w+\.W135/');
if missing(re) then do; putlog 'ERROR: evil regex loose!'; stop; end;
if prxmatch(re, VarToBeChecked);
David L. Cassell
3115 NW Norwood Pl.
Corvallis OR 97330
Donít just search. Find. Check out the new MSN Search!