SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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