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

I have some data on employment types but it's in a slightly odd format and would love some assistance fixing this. 

The data has no spaces in it, but does (mostly) have a capital letter designating the start of the second or nth work.  I would like to create a new variable that takes this employment type and inserts a space where it sees a capital letter. 

EG;

Have

EmpType

SteelIndustry

ClothingTrade 

 

Want

NewEmpType

Steel Industry

Clothing Trade

 

One slight stumbling block is that there are some words that have been capitalised that should remain that way and not have spaces inserted. 

EG;  GovernmentUSA = Government USA.  LTDTrader = LTD Trader.

 

Finally, there are some odd ones in here like Universityprofessor.  Now I know what that should be by looking at it, but if anyone has any suggestions as to how to fix scenarios like that i'd be very impressed!

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

That is very complicated. You need get a word list dictionary.

 

data have;
input have $20.;
want=strip(compbl(prxchange('s/([A-Z][a-z]+)/ $1 /',-1,have)));
cards;
EmpType
SteelIndustry
ClothingTrade 
GovernmentUSA 
LTDTrader 
;

View solution in original post

3 REPLIES 3
Ksharp
Super User

That is very complicated. You need get a word list dictionary.

 

data have;
input have $20.;
want=strip(compbl(prxchange('s/([A-Z][a-z]+)/ $1 /',-1,have)));
cards;
EmpType
SteelIndustry
ClothingTrade 
GovernmentUSA 
LTDTrader 
;
Jamie_H
Fluorite | Level 6
This works great, thank you very much!
ballardw
Super User

Since you are inserting characters you may need to create a new variable that is longer than your existing one. If any of your current values are exactly the defined length of the variable then when you insert a character in the middle the end of the value will get truncated.

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1089 views
  • 1 like
  • 3 in conversation