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,

 

I import an excel file, the data has the line breaks, so, sometimes ,in my sas data I have the multiple spaces.

I want to replace this spaces by  ^n but my code doesn't work:

 

OBJECTIVES2=prxchange('s/(^|\b)\s{2,}(\b|$)/^n/oi',-1,OBJECTIVES);

 

Maybe you know some other options to do that?

 

 

Thank you for your help!

Best regards,

Marie

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

A space means \b is matched, so I am unsure what the intent of your expression is.

 

> I want to replace this spaces by  ^n 

Like this? It's the same as your expression.

OBJECTIVES2=prxchange('s/\s{2,}/^n/',-1,OBJECTIVES);

 

 

View solution in original post

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

A space means \b is matched, so I am unsure what the intent of your expression is.

 

> I want to replace this spaces by  ^n 

Like this? It's the same as your expression.

OBJECTIVES2=prxchange('s/\s{2,}/^n/',-1,OBJECTIVES);

 

 

SASdevAnneMarie
Barite | Level 11
Great! It works! Thank you!
Patrick
Opal | Level 21

I would remove the line breaks from your data. That's only going to create problems "somewhere".

Below RegEx replaces one or multiple consecutive whitespace characters with a single blank.

OBJECTIVES2=OBJECTIVES;
OBJECTIVES2=prxchange('s/\s+/ /oi',-1,OBJECTIVES2);

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 3 replies
  • 905 views
  • 0 likes
  • 3 in conversation