BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
LRogers
Obsidian | Level 7

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:

LRogers_1-1746728623982.png

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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.

 

Quentin
Super User

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."

The Boston Area SAS Users Group is hosting free webinars!
Next up: SAS Trivia Quiz hosted by SAS on Wednesday May 21.
Register now at https://www.basug.org/events.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

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.

 

Register now

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
  • 2 replies
  • 330 views
  • 0 likes
  • 3 in conversation