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
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 ;
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 ;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.