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.
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!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: