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 (August 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 12 Aug 2004 15:39:37 -0500
Reply-To:     "Waks, Willy" <wwaks@TI.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Waks, Willy" <wwaks@TI.COM>
Subject:      Re: Perl Expression in SAS 9
Comments: To: "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
Content-Type: text/plain; charset="us-ascii"

Chang: If there is more than one space surrounding the libref, how should we deal with this ? libname appldata '~/dlp_old/DMD/int_yield/appldata '; Thanks. Willy Waks

-----Original Message----- From: Chang Y. Chung [mailto:chang_y_chung@HOTMAIL.COM] Sent: Thursday, August 12, 2004 3:34 PM To: SAS-L@LISTSERV.UGA.EDU; Waks, Willy Subject: Re: Perl Expression in SAS 9

On Thu, 12 Aug 2004 12:59:19 -0500, Waks, Willy <wwaks@TI.COM> wrote:

>To All Perl Experts: >I am trying to use the new PRX functions in SAS 9, but I am novice at >Perl. I want to extract libref and path from a sas program which >contains may libname statements such as this: > >libname appldata '~/dlp_old/DMD/int_yield/appldata '; >libname _105714 '~/dlp_old/Data/105714 '; > >(all my path start with '~/dlp_old/) which helps.) >I know how to do that with a combo of prx and good ols substr and scan >functions: > > filename myauto '~/dlp_old/autoexecadm.sas'; > data dsn(keep=dsn mylib); > infile myauto; > length dsn $40. mylib $8; > retain pref ; > input; > if _n_=1 then pref=prxparse("[~/dlp_old/*]"); > if prxmatch(pref,_infile_) then do; > call prxsubstr(pref,_infile_,pos,length); > dsn=scan(substr(_infile_,pos),1,"'"); > mylib=scan(substr(_infile_,1,pos),2," "); > output; > end; > run; > >What prx could I substitute to get the same results ? >Thanks

Hi, Willy,

How about prxChange function to change the line into whatever you want to extract, like below. I've also re-wrote your prx for libname line matching. HTH.

Cheers, Chang

options nocenter; data one(keep=dsn mylib);

length libname $80; length prxLibname prxDsn prxMyLib 8; length dsn $40 mylib $40;

infile cards; input;

if _n_=1 then do; /* your libname line:

starts with "libname" , followed by a space , then a sas name , followed by a space , then a single quoted path string , then a semi-colon , then optional spaces

dsn and MyLib parts are in parentheses so that we can refer to them with $#. */ libname = "|libname\s(\w+)\s\'(.+)\'\;\s*|"; prxLibname = prxParse(libname); prxMyLib = prxParse(cats("s", libname, "$1|")); prxDsn = prxParse(cats("s", libname, "$2|")); retain prx:; end;

if prxmatch(prxLibname, _infile_) then do; dsn = prxChange(prxDsn, 1, _infile_); myLib = prxChange(prxMyLib, 1, _infile_); output; end;

cards4; libname appldata '~/dlp_old/DMD/int_yield/appldata '; libname _105714 '~/dlp_old/Data/105714 '; ;;;; run; proc print data=one; run; /* on lst Obs dsn mylib

1 ~/dlp_old/DMD/int_yield/appldata appldata 2 ~/dlp_old/Data/105714 _105714 */


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