BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vbylsma
Fluorite | Level 6

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? 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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
;

View solution in original post

5 REPLIES 5
Reeza
Super User
Your examples all seem to have it at the end and same pattern. Can you provide a more representative example and also include what you're looking for as your final output.
Astounding
PROC Star
Given that the string always begins the final word, here's one way:

delete_here = index(unit, ' OL');
if delete_here then
unit = substr(unit, 1, delete_here);
vbylsma
Fluorite | Level 6
This also worked, thank you so much!
Ksharp
Super User
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
;
vbylsma
Fluorite | Level 6
This worked AND I learned a lot about PRXCHANGE. Thank you!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1199 views
  • 2 likes
  • 4 in conversation