BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11

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 !

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

@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?

View solution in original post

5 REPLIES 5
maguiremq
SAS Super FREQ

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://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0r8h2fa8djqf1n1cnenrvm573br.h... 

https://support.sas.com/rnd/base/datastep/perl_regexp/regexp-tip-sheet.pdf 

 

andreas_lds
Jade | Level 19

@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?

AnujaNagpal
SAS Employee

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. 

Ksharp
Super User
It is depended on what you need after COMPRESS().

data have;
x = "TYPE 1 INDEX 2";
y = compress(x,' ','kw');
run;
Oligolas
Barite | Level 11

Hi,

You may be looking for this

compbl(X||' '||'P3')
________________________

- Cheers -

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 964 views
  • 5 likes
  • 6 in conversation