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 (March 1999, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sat, 6 Mar 1999 17:47:14 +0000
Reply-To:   John Whittington <medisci@POWERNET.COM>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   John Whittington <medisci@POWERNET.COM>
Subject:   Re: Replace String
Comments:   To: Jin Man Lee <jlee20@UIC.EDU>
Content-Type:   text/plain; charset="us-ascii"

At 01:04 06/03/99 -0600, Jin Man Lee wrote:

>I am working on string matching project. Anybody has a good idea >to replace some character on a variable? >For example, > FOX VLY -> FOX VALLEY > GREEN VLG -> GREEN VILLAGE

Jinman, the TRANWRD() function is probably your answer, although you will have to hardcode each of the decodings you want. One was to do it is this:

Given a dataset 'test' which contains values for 'a' of:

FOX VLY GREEN VLG GREEN VLY FOX VLG FOX TWN GREEN TWN FOX NO_CHANGE

.. then the following code:

data showit ; length a b $30 ; set test ; b = tranwrd(a, 'VLY', 'VALLEY') ; b = tranwrd(b, 'VLG', 'VILLAGE') ; b = tranwrd(b, 'TWN', 'TOWN') ; run ; proc print ; run ;

... will give you output:

OBS A B

1 FOX VLY FOX VALLEY 2 GREEN VLG GREEN VILLAGE 3 GREEN VLY GREEN VALLEY 4 FOX VLG FOX VILLAGE 5 FOX TWN FOX TOWN 6 GREEN TWN GREEN TOWN 7 FOX NO_CHANGE FOX NO_CHANGE

Any help?

Regards,

John

---------------------------------------------------------------- Dr John Whittington, Voice: +44 (0) 1296 730225 Mediscience Services Fax: +44 (0) 1296 738893 Twyford Manor, Twyford, E-mail: medisci@powernet.com Buckingham MK18 4EL, UK mediscience@compuserve.com ----------------------------------------------------------------


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