Date: Sun, 3 Aug 2008 12:28:13 -0400
Reply-To: Ken Borowiak <EvilPettingZoo97@AOL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ken Borowiak <EvilPettingZoo97@AOL.COM>
Subject: Re: Regex
On Sun, 3 Aug 2008 05:39:38 -0400, Stephane COLAS <scolas@DATAMETRIC.FR> wrote:
>Hi Ken ,
>
>It's great. Thanks. I created something dirty in the meantime :
>
>FindFilename=prxParse('s/([a-zA-Z0-9=, :\\]*)(filename[=
>]*)([a-zA-Z]*)(.txt)([a-zA-Z0-9=, :\\]*)/$3/');
>CALL prxChange (FindFilename,1,c,Target,newLength,wasTruncated,numberFinds);
>if numberFinds = 0 then Target ='';
>
>I have to undertand why you use this syntax now ...
>
>Ken, In the same DATA step I would like to save the path name of my work and
>replace the path= value by this Path name. Could you explain to me how to do
>that with PRXCHANGE ??
>
>data cc;
>length work $200 Before $ 60 After $ 60 ;
>input Before $60.;
>
>work=pathname("work");
>
>
>
>datalines;
> filename=Premier.txt, path=toto
>a=1, b=2 , filename=John.txt, path=c:\temp
>filename=John.txt,a=1, b=2 , path=c:\temp
>path=c:\temp, filename=John.txt,a=1, b=2
>a=1,b=2,filename= BaaBaa.txt
>a=1, b=2, path=toto
>Prince
>;
>
Stephanie,
To replace the text following 'PATH=' with the location of your WORK
library, try the following.
data ccc ;
input c $60. ;
datalines ;
filename=Premier.txt, path=toto
a=1, b=2 , filename=John.txt, path=c:\temp
filename=John.txt,a=1, b=2 , path=c:\temp
path=c:\temp, filename=John.txt,a=1, b=2
a=1,b=2,filename= BaaBaa.txt
a=1, b=2, path=toto
Prince
;
run ;
* get path for WORK ;
%let pathname=%sysfunc( pathname(work) ) ;
%put Path for WORK: &pathname ;
* Perform the replacement ;
data better ;
set ccc ;
re=prxparse( "s/(?<=path=)\s*(?:[\w:\\]+)/&pathname/io" ) ;
length new_c $100 ;
new_c=prxchange( re, -1, c ) ;
run ;
Regards,
Ken
|