Hello Experts,
I'm wondering how to hold the spaces while using the compress function. The values of my variable is X='TYPE 1 INDEX 2'.
When I use compress(X||' '||'P3') I have 'TYPE1INDEX2 P3', I would like to have TYPE 1 INDEX 2 P3
There is some option for compress function please or, in this case, the STRIP function is better ?
Thank you for helping !
@SASdevAnneMarie wrote:
Hello Experts,
I'm wondering how to hold the spaces while using the compress function. The values of my variable is X='TYPE 1 INDEX 2'.
When I use compress(X) I have 'TYPE1INDEX2'.
Thank you for helping !
But, why are you calling compress?
I can't tell if this is what you want, but it seemed like a variant that's acceptable.
data have;
x = "TYPE 1 INDEX 2";
y = prxchange("s/(?<!\d)\s//", -1, x);
run;
Obs x y 1 TYPE 1 INDEX 2 TYPE1 INDEX2
If you're unfamiliar with regular expressions, these resources will be helpful.
https://support.sas.com/rnd/base/datastep/perl_regexp/regexp-tip-sheet.pdf
@SASdevAnneMarie wrote:
Hello Experts,
I'm wondering how to hold the spaces while using the compress function. The values of my variable is X='TYPE 1 INDEX 2'.
When I use compress(X) I have 'TYPE1INDEX2'.
Thank you for helping !
But, why are you calling compress?
Can you share what are you expecting the output to look like? Compress might not be the right choice of function here based on what you are trying to do.
Hi,
You may be looking for this
compbl(X||' '||'P3')
- Cheers -
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 25. 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.