data test;
input name $25.;
cards;
x., test
.x test
test x.
;
run;
data want;
set test;
a=prxchange('s/\b(x\.,|x\.|\x)\b//i', -1, name);
run;
Hello there!
I'm trying to extract from string literal all parts which looks like x or x. or x.,
So I've wrtitten the code above
A result dataset you can see in the table below
It seems that SAS had deleted only x character, not x. or x.,
despite fact of existence x\. and x\., in regular expression before x
Does anyone know how it could be fixed?
Resulted dataset:
name | a | |
1 | x., test | ., test |
2 | .x test | . test |
3 | test x. | test . |
Desired dataset:
name | a | |
1 | x., test | test |
2 | .x test | . test |
3 | test x. | test |
Hello @Ga1ath and welcome to the SAS Support Communities!
I see two issues:
Try this regex instead:
a=prxchange('s/\b(x\.,|x\.|x\b)//i', -1, name);
Hello @Ga1ath and welcome to the SAS Support Communities!
I see two issues:
Try this regex instead:
a=prxchange('s/\b(x\.,|x\.|x\b)//i', -1, name);
Thank you for reply!
All clear except second issue. You'h wrote The "\x" in your regular expression should read "|x".
But I don't see \x in my primordial regular expression. Please, can you explain what you have meant?
@Ga1ath wrote:
All clear except second issue. You'h wrote The "\x" in your regular expression should read "|x".
But I don't see \x in my primordial regular expression. Please, can you explain what you have meant?
I meant this:
@Ga1ath wrote:
data want; set test; a=prxchange('s/\b(x\.,|x\.\x)\b//i', -1, name); run;
whereas
@FreelanceReinh wrote:
a=prxchange('s/\b(x\.,|x\.|x\b)//i', -1, name);
Of course, yeah. I'm sorry for my inattention.
Is that last table supposed to be what you want to produce? Or is it the wrong output your current code is producing? If the latter then please provide the desired results for your example input.
It is the wrong output. I'll edit the post.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: