Sas remove blanks from string

Next code tells compress function which characters to keep,

a=alpha, d=digits, p=punctuation, k=keep:

new_var = compress(var, ,'kadp');

try it and adapt to your needs.

More characters in the link posted by @Reeza

6 REPLIES 6 Super User Re: How to remove space or special char in string? Posted 10-18-2020 04:39 PM (10192 views) | In reply to sasecn

Spaces are not necessarily blanks, so there's an option within the COMPRESS functions to handle multiple different types of spaces, it's the third example in the documentation. That adding in that modifier (third parameter) and see if it works for you.

data one; x='1 2 3 4 5'; y=compress(x, , 's'); put y=; run; 
@sasecn wrote:

Hello:

I am trying to remove space inside strings, e.g. remove the space before "1" in the string "XXX-1234. 1". I have many values in the same format i.e. "XXX-####.#". Many of them have space after the "." and before the last digit. I would like to remove any space in the strings. Some of them can be removed successfully by using compress(). But some of them, the space cannot be removed by compress().

Not sure if the space was from some special char or something else than typing. How can I identify and remove them.

Any help?

Thanks,