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).
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.