Date: Sun, 5 Nov 2006 14:28:17 -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: Replacing a sign in a data value
In-Reply-To: <3ZednTocVJQSAdHYRVnzvQ@telenor.com>
Content-Type: text/plain; format=flowed
rune@FASTLANE.NO wrote back:
>
>This is still not getting through without error messages.
>
>
>data myds;
> infile datalines truncover pad ;
> input @01 line $char140.;
> *old code;
>* call prxchange( 's/SAKSNR:\s+\d{4}(\d)\d+/\//', 1, _infile_ );
>
> * new code;
> re = prxparse('s/(SAKSNR:\s+\d{4})\d(\d+)/\1/\2/');
> call prxchange( re, 1, _infile_);
>
> file "d:\myds.txt";
> put _infile_;
> datalines;
>-----------------------------------
>SAKSNR: 1994000003
>ARKIV: 046.5
>TITTEL: something
>SAKSDATO: 06.01.1994
>
> DOKNR: 1
> DOKTYPE: I
> DOK.TITTEL
> AVSKR.DOK 2
>-----------------------------------
> ;
> run;
>
>
>part of the log:
>
>ERROR: Invalid characters "\2/" after end delimiter "/" of regular
>expression
> "s/(SAKSNR:\s+\d{4})\d(\d+)/\1/\2/".
>ERROR: The regular expression passed to the function PRXPARSE contains a
>syntax error.
>NOTE: Argument 1 to function PRXPARSE at line 295 column 9 is invalid.
>NOTE: Argument 1 to the function PRXCHANGE is missing.
>NOTE: Argument 1 to function PRXCHANGE at line 296 column 9 is invalid.
>
>
>Regards, Rune
>
>
>
>
>"David L Cassell" <davidlcassell@MSN.COM> wrote in message
>news:BAY103-F622098FBDE04A91CA732EB0FE0@phx.gbl...
> > rune@FASTLANE.NO wrote back:
> >>
> >>Hi,
> >>You have descibed in words what you did do correct the fault. But did
> >>you forget to post the code ?
> >>
> >>Rune
> >>
> >>
> >>David L Cassell wrote:
> >>
> >> >
> >> > I think the error message means that we can put matches in the
> >> > function, but we cannot put substitutions in. So we have to put
> >> > the substitution component s/pattern/changes/ in the PRXPARSE()
> >> > function, as I did this time. Note that I left out the usual IF
>_N_=1
> >> > part I like, along with error-checking.
> >> >
> >> > And I changed the pattern. This time we match SAKSNR: plus some
> >> > spaces plus 4 digits, and we put that in buffer $1, we match the
>fifth
> >> > digit, then we put the rest of the digits in pattern buffer $2. So
>the
> >> > change we make is to what is in $1, a /, and what is in $2.
> >> >
> >> > We do have limits on the functionality we can use in PRX functions,
> >> > because components have to be processed, sent to a separate regex
> >> > engine under the hood, and then passed back. This look like one
> >> > (rather minor) limit.
> >> >
> >> > HTH,
> >> > David
> >
> > Well, I *thought* I pasted it in, but it may have been inadvertently
> > translated into a MIME attachment and scragged by the lsitserv. Or
> > maybe it's my bad karma.
> >
> > Let's see. What could that code have been? This is probably within
> > epsilon:
> >
> > re = prxparse('s/(SAKSNR:\s+\d{4})\d(\d+)/\1/\2/');
> > call prxchange( re, 1, _infile_);
> >
> > HTH,
> > David
> > --
> > David L. Cassell
> > mathematical statistician
> > Design Pathways
re = prxparse('s/(SAKSNR:\s+\d{4})\d(\d+)/$1/$2/');
Sorry. You can use \1 and \2 to represent the capture
buffers in the first part - the pattern part - but you should
use $1 and $2 to represent the contents of the capture
buffers in the second part - the 'what we want to substitute
in for the pattern' part.
David
--
David L. Cassell
mathematical statistician
Design Pathways
3115 NW Norwood Pl.
Corvallis OR 97330
_________________________________________________________________
Add a Yahoo! contact to Windows Live Messenger for a chance to win a free
trip!
http://www.imagine-windowslive.com/minisites/yahoo/default.aspx?locale=en-us&hmtagline
|