Hello!
I have a string values in a dataset that I would like to cleanup so there's only one space between each word.
There are some cases where there's two spaces so it's creating a separate value.
Here's an example:
The first one has multiple spaces between "IT" and "INC", whereas the second one just has one space (desired).
I've researched trim, strip, compress - having trouble finding the solution.
Thanks!
P.S I'm using Enterprise Guide
I doubt if Enterprise Guide has any GUI tools to handle this, so just write normal SAS code instead.
If the white spaces are actual tabs just use the COMPBL() function to collapse the multiple adjacent spaces into one.
string=compbl(string);
If you also need to remove leading spaces use LEFT() function. Don't worry about trailing spaces, SAS variables are fixed length and padded with spaces, so any trailing spaces you remove will just reappear once you store the value back into a variable.
I doubt if Enterprise Guide has any GUI tools to handle this, so just write normal SAS code instead.
If the white spaces are actual tabs just use the COMPBL() function to collapse the multiple adjacent spaces into one.
string=compbl(string);
If you also need to remove leading spaces use LEFT() function. Don't worry about trailing spaces, SAS variables are fixed length and padded with spaces, so any trailing spaces you remove will just reappear once you store the value back into a variable.
Try the COMPBL function. From the docs:
"The COMPBL function removes multiple blanks in a character string by translating each occurrence of two or more consecutive blanks into a single blank."
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.