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

Hello,

I have simple task - replace new line symbol to simple space character.

So some sas table has character cell and this cell has long string with new line characters inside, and I need just replace all these symbols to space symbols.

Looks like this task can be simple resolved by simple sas perl function:

...

prxchange("s/X/ /",-1,ColName);

...

Where X- new line character(or appropriate code) that I actually can't find , and ColName is the name of character column that has this new lines symbols.

Will be grateful for any help!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

new line character is \n in Perl Regular Expression.

prxchange("s/\n/ /",-1,ColName);

Ksharp

View solution in original post

10 REPLIES 10
Ksharp
Super User

new line character is \n in Perl Regular Expression.

prxchange("s/\n/ /",-1,ColName);

Ksharp

Yura2301
Quartz | Level 8

Hi Ksharp,

Thanks, it helped.Before I tried same /n character but inside of quote('/n' istead of simple /n) that's why it didn't helped.

Thanks once more!

Tom
Super User Tom
Super User

Regular expression is overkill for such a simple task.

You can use translate to replace single characters with other characters. Note that the order of the arguments to translate seems backwards, which I assume you can blame on the IBM mainframe command that SAS used in the old days.

translate(ColName,' ','0A'x)

Also you can use TRANWRD to replace substrings with replacement text.

tranwrd(ColName,'0A'x,' ')
Yura2301
Quartz | Level 8

Hi Tom,

Thanks, I supposed that perl fucntion will perfom this operation fuster, but may be really simple tranwrd function will work quicker, I'll look into it.

Thanks!

Doc_Duke
Rhodochrosite | Level 12

Yura,

One other comment.  The newline "character" means different things on different operating systems.  So Tom's '0A'x would work for Unix (which just uses the linefeed as a newline marker).  Windows uses the two character combination of <CR><LF> to mark the end of a line ('0D'x).

The perl function knows which OS you are on and adjusts accordingly.

Doc Muhlbaier

Duke

Yura2301
Quartz | Level 8

Thanks Doc!

FriedEgg
SAS Employee

using the regular expression prxchange('s/\r?\n/ /o',-1,foo) will take care of cases for newlines with or without carriage returns.

Yura2301
Quartz | Level 8

Thanks!

gee
Calcite | Level 5 gee
Calcite | Level 5

Thanks this expression helping out me a lot.

maheshtalla
Quartz | Level 8

Hi Ksharp,

I was also facing the same issue.  After searching a lot, i found this and it was very helpful.

Thanks a lot.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 10 replies
  • 49427 views
  • 10 likes
  • 7 in conversation