Date: Wed, 27 Sep 2006 17:25:48 -0400
Reply-To: AG <saslmem@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: AG <saslmem@GMAIL.COM>
Subject: Re: How to get "YET???" to become "YET?"
In-Reply-To: <200609272026.k8RKI9pZ028317@mailgw.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hi Chang,
The reason i used -1 was to replace multiple occurences of mutiple
"????"
for example - consider the data one(with length statement) set below. note
that the first obs has several instances of "???"
data one;
length x $20;
input x $;
cards;
one???asfdkaj???klasjfd???
two??
three???
four????
five????
;
data two;
length justone $20;
set one;
justone=prxchange('s/\?+/?/',1,x);
run;
The above code with positive one (1) will replace only the first bunch of
"???" in the first observation. output of which is as follows.
* Obs justone x
* 1 one?asfdkaj???klasjfd??? one???asfdkaj???klasjfd???
2 two? two??
3 three? three???
4 four? four????
5 five? five????
Now if you use the negative one(-1). It replaces all the instances of "???".
* Obs justone x*
1 one?asfdkaj?klasjfd?
one???asfdkaj???klasjfd???
2 two? two??
3 three? three???
4 four? four????
5 five? five????
Cheers,
ag
On 9/27/06, Chang Chung <chang_y_chung@hotmail.com> wrote:
>
> On Wed, 27 Sep 2006 11:34:50 -0400, Charles Patridge
> <charles_s_patridge@PRODIGY.NET> wrote:
>
> >Thanks for the assistance - I am going to use AG's solution - much
> shorter
> >and to the point - sorry <grin>
> >
> >The following should do it.
> >
> > data one;
> > input x $;
> > cards;
> > one?
> > two??
> > three???
> > four????
> > five?????
> > ;
> > run;
> >
> > data two;
> > set one;
> > justone=prxchange('s/\?+/?/',-1,x);
> > run;
> ...
>
> Hi,
>
> I wouldn't go with the data step two above, since I am not sure if I have
> explicit control over the length of the new variable, justone. So, I would
> put a length statement (or a retain or attrib or just an assignment or
> whatever...). Also the negative one (-1) does not make sense because the
> goal seems to replace the trailing conjecutive multiple quotation marks
> into
> one. If this is what you aim for and you should not do (-1) since it would
> do much more. So, it comes down to something like:
>
> data three;
> set one;
> length justone $8;
> justone=prxchange('s/\?+/?/',1,x);
> run;
>
> Now given this neccessary modification, it looks so much like (sas) rx
> solution:
>
> data four;
> set one;
> length justone $8;
> call rxchange(" '?'+ to '?' ", 1, x, justone);
> run;
>
> Or, it seems to me that the sas rx looks much easier to read than prx
> solution. :-)
>
> I totally agree with data _null_ in that the guy who wrote sas rx is not
> bad
> at all. I rather feel that si lost an opportunity to make sas's version of
> rx much more powerful by switching to perl rx. By definition, perl rx is
> made to work in perl not in sas. So perl rx in sas will always be
> something
> short of the real perl rx running inside perl. si could have extended sas
> rx
> so that it could take full advantage of sas such as calling sas data step
> functions or statements inside the rx, for example. If compatibility was
> an
> issue, then si could have made the sas rx an open source and given it away
> free, too, as perl did... I know I am dreaming :-)
>
> Cheers,
> Chang
>
|