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 -
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.