I am standardizing unit names, however many of them contain a non-standard indicator at the end of the unit name (it denotes geographically separated but part of the same unit). I need to remove this final string so these units can later be combined into one unit. Typically I would substring this, but the indicator 1) does not occur on every unit name, 2) is not in a standard position in the string, and 3) the final sting itself isn't consistent in the use of digit vs character starting in position 3 (see below).
Examples of the unit names:
SURGICAL OPS OLA900
SURGICAL OPS OLHC00
EDU AND TRNG OL0IZH
EDU AND TRNG OL0PZR
LEGAL OLCS00
LEGAL OLA200
The final sting always starts with " OL". Searches have brought me to PRXCHANGE, but as I've read in forums and found out myself, the syntax is particularly confusing. What is your best practice recommendation in this situation?
data have;
input have $40.;
want=prxchange('s/\bOL\w+$//i',1,strip(have));
cards;
SURGICAL OPS OLA900
SURGICAL OPS OLHC00
EDU AND TRNG OL0IZH
EDU AND TRNG OL0PZR
LEGAL OLCS00
LEGAL OLA200
;
data have;
input have $40.;
want=prxchange('s/\bOL\w+$//i',1,strip(have));
cards;
SURGICAL OPS OLA900
SURGICAL OPS OLHC00
EDU AND TRNG OL0IZH
EDU AND TRNG OL0PZR
LEGAL OLCS00
LEGAL OLA200
;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.