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!
new line character is \n in Perl Regular Expression.
prxchange("s/\n/ /",-1,ColName);
Ksharp
new line character is \n in Perl Regular Expression.
prxchange("s/\n/ /",-1,ColName);
Ksharp
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!
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,' ')
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!
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
Thanks Doc!
using the regular expression prxchange('s/\r?\n/ /o',-1,foo) will take care of cases for newlines with or without carriage returns.
Thanks!
Thanks this expression helping out me a lot.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.