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 (December 1999, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 22 Dec 1999 15:19:56 -0500
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
Subject:      Re: Replacing/Deleting an occurrence of a string in a field
Content-Type: text/plain; charset=US-ASCII

<<Jim Link asks>> I have an approximately 32 character field in a couple SAS data sets that I am trying to match up. One of the problems caused in the matching is that " INC " and " CORP " (with spaces so they are not part of the name) are sometimes mixed and matched. While I can easily compress out instances of single characters, I do not know how to compress out and/or replace instances of a whole string with another whole string. That is, I'd like to do a couple things: 1. Get rid of all instances of " INC " and " CORP " in the variable 2. Replace all instances " INC " with " CORP " <<end quote>>

Once again, Tech Report P-222 comes to the rescue, in the form of the TRANWRD function:

DATA _NULL_; LENGTH OldVar NewVar1 $ 32 NewVar2 $ 33; /* Use & to include single embedded blanks in value */ INPUT OldVar &; NewVar1 = TRANWRD(OldVar, ' INC ', ' '); NewVar1 = TRANWRD(NewVar1, ' CORP ', ' '); NewVar2 = TRANWRD(OldVar, ' INC ', ' CORP '); PUT _ALL_; CARDS; SAS INSTITUTE INC MICROSOFT INC CORNING CORP WESTAT RUN;

Mike Rhoads Westat (neither CORP nor INC)

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