|
<<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)
RhoadsM1@Westat.com
|