Hello,
I'm trying to replace more than one space by ^n,
But my code doesn't work:
data OBJ1;
set OBJ2;
rx = prxparse('s/(\w+ \w*) +.*/^n/');
call prxchange(rx,-1,OBJECTIVES);
run;
Do you know please some options to replace more than two spaces?
Thank you for your help!
Best regards,
Marie
Please try the below code , in the example below in objectives variable we have sample1 followed by two spaces number 2 and then number 3 with one space and it replaced only the two spaces between 1 and 2 with ^n
data OBJ1;
OBJECTIVES='sample1 2 3 4 5 6';
new=prxchange('s/\b\s{2,}\b/^n/oi',-1,OBJECTIVES);
run;
Please try the below code , in the example below in objectives variable we have sample1 followed by two spaces number 2 and then number 3 with one space and it replaced only the two spaces between 1 and 2 with ^n
data OBJ1;
OBJECTIVES='sample1 2 3 4 5 6';
new=prxchange('s/\b\s{2,}\b/^n/oi',-1,OBJECTIVES);
run;
Small update if I may, to cover leading and trailing spaces:
data OBJ1;
OBJECTIVES=' sample1 2 3 4 5 6 ';
new=prxchange('s/(^|\b)\s{2,}(\b|$)/^n/oi',-1,OBJECTIVES);
put _all_;
run;
Bart
What happened to plain old cmpbl (compressible function).
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.