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 (September 2009, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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?

Hi there,

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_; 2 a='abc'||'09'x||'xyzaf'||'09'x||'abc'||'09'x; 3 put a=; 4 run;

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'.

Thanks.

Ya


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