Date: Wed, 16 Sep 2009 17:47:25 -0400
Reply-To: Ya Huang <ya.huang@AMYLIN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ya Huang <ya.huang@AMYLIN.COM>
Subject: replacing the nth substring in a tab delimited long string?
Assume that I have a long string which is composed of short strings,
delimited by tab. I want to replace the Nth substring with a fixed
word. Wonder if someone has a good way to do it.
1 data _null_;
3 put a=;
a=abc xyzaf abc
Let's say, I want to replace the 3rd substring, which is 'abc'
with 'XXX'. I thought about using scan(a,n,'09'x) to get the
nth substring, then use tranwrd to replace it. But the problem
is that the long string may have duplicated substring, tranwrd
will replace all of them. For the above example, we have two 'abc'.