I have a column called "Name" which stores the 8 states and territories in Australia, all upper-cased and spacing replaced with an underscore (i.e. NEW_SOUTH_WALES, VICTORIA, QUEENSLAND, SOUTH_AUSTRALIA, WESTERN_AUSTRALIA, TASMANIA, NORTHERN_TERRITORY, AUSTRALIAN_CAPITAL_TERRITORY). My aim is to create a separate column where the state names are proper case with spacing, so I created 3 individual columns that split the names.
Word1=propcase(scan(Name,1,'_'));
Word2=propcase(scan(Name,2,'_'));
Word3=propcase(scan(Name,3,'_'));
After this step, I used
Word=cat(Word1,Word2,Word3);
to create the column with space in between. However, it only gives me a blank column instead. How can I resolve this?
You could use:
Word = propcase(translate(Name, ' ', '_'));
Don't forget to use the length-statement so that the length of "Word" is sufficient.
Use the CATX function:
Word = catx(" ",Word1,Word2,Word3);
The extended CAT functions remove leading and trailing blanks on their own.
You could use:
Word = propcase(translate(Name, ' ', '_'));
Don't forget to use the length-statement so that the length of "Word" is sufficient.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.
Find more tutorials on the SAS Users YouTube channel.