LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 7 Dec 2005 02:35:46 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: Wild card equivalent in SAS ?
Comments: To: davidlcassell@MSN.COM
In-Reply-To:  <BAY103-F203C9CA47D3681525699C2B0430@phx.gbl>
Content-Type: text/plain; format=flowed


Uhhhh clear as muddy water...

Toby Dunn

From: David L Cassell <davidlcassell@MSN.COM> Reply-To: David L Cassell <davidlcassell@MSN.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Wild card equivalent in SAS ? Date: Tue, 6 Dec 2005 17:06:11 -0800

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!

Back to: Top of message | Previous page | Main SAS-L page