Help using Base SAS procedures

SAS new line symbol character code?

Accepted Solution Solved
Reply
Regular Contributor
Posts: 161
Accepted Solution

SAS new line symbol character code?

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!


Accepted Solutions
Solution
‎01-11-2012 03:39 AM
Super User
Posts: 10,035

SAS new line symbol character code?

new line character is \n in Perl Regular Expression.

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

Ksharp

View solution in original post


All Replies
Solution
‎01-11-2012 03:39 AM
Super User
Posts: 10,035

SAS new line symbol character code?

new line character is \n in Perl Regular Expression.

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

Ksharp

Regular Contributor
Posts: 161

SAS new line symbol character code?

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!

Super User
Super User
Posts: 7,054

Re: SAS new line symbol character code?

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,' ')
Regular Contributor
Posts: 161

Re: SAS new line symbol character code?

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!

Trusted Advisor
Posts: 2,116

SAS new line symbol character code?

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

Regular Contributor
Posts: 161

Re: SAS new line symbol character code?

Thanks Doc!

Trusted Advisor
Posts: 1,301

Re: SAS new line symbol character code?

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

Regular Contributor
Posts: 161

Re: SAS new line symbol character code?

Thanks!

New Contributor gee
New Contributor
Posts: 2

Re: SAS new line symbol character code?

Thanks this expression helping out me a lot.

Contributor
Posts: 66

Re: SAS new line symbol character code?

Hi Ksharp,

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

Thanks a lot.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 16241 views
  • 9 likes
  • 7 in conversation