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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1218 views
  • 1 like
  • 3 in conversation