[prev in list] [next in list] [prev in thread] [next in thread]
List: sas-l
Subject: Re: How to delete (replace) specific characters in an irregular
From: "Dunn, Toby" <Toby.Dunn () TEA ! STATE ! TX ! US>
Date: 2004-11-30 20:11:35
[Download RAW message or body]
Ahhh yes but tranwrd runs faster.
Toby
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Laurie Fleming
Sent: Tuesday, November 30, 2004 1:50 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: How to delete (replace) specific characters in an irregular
string
In article <200411301642.iAUGggSY014677@listserv.cc.uga.edu>,
xt_zhong@YAHOO.COM (Shelton Zhong) wrote:
> suppose
>
> data t1;
> x='ab, 6, c, def';
> y='h, i, jk';
> run;
>
> Is there a simple way to knock out the ','s in x and y , that is to
> replace ',' with 0 length empty place. As you see, x and y have
> irregular patterns. The SUBSTR(Left of =) function needs specific
> character positions, and the approach using INDEX() and SCAN()
> fucntions seems to be too complicated. Thanks!
It couldn't be easier, Shelton. Have a look at this:
1 data t1;
2 x='ab, 6, c, def';
3 y='h, i, jk';
4 new_x = compress(x, ',');
5 new_y = compress(y, ',');
6 put new_x= new_y=;
7 run;
new_x=ab 6 c def new_y=h i jk
The compress function by default removes spaces; when you provide a
second parameter, all the characters in the second parameter are
removed. In version 9 there is a third parameter, modifier, which
provides extra functionality.
If you wanted to keep the places where the commas were, the translate
function would be best: new_x = translate(x, ' ', ',');
Note that the parameters are: variable, to, from - not the more logical
variable, from, to.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic