- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 !
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
x = "TYPE 1 INDEX 2";
y = compress(x,' ','kw');
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You may be looking for this
compbl(X||' '||'P3')
- Cheers -