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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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