BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ga1ath
Fluorite | Level 6
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 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:

 namea
1x., test., test
2.x test. test
3test x.test .

 

Desired dataset:

 namea
1x., testtest
2.x test. test
3test x.test
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @Ga1ath and welcome to the SAS Support Communities!

 

I see two issues:

  1. A word boundary (PRX metacharacter \b) cannot occur directly after a comma or a period because by definition it is "the position between a word and a space" -- but neither the comma nor the period is a word character (cf. PRX metacharacter \w).
  2. The "\x" in your regular expression should read "|x".

Try this regex instead:

a=prxchange('s/\b(x\.,|x\.|x\b)//i', -1, name);

View solution in original post

6 REPLIES 6
FreelanceReinh
Jade | Level 19

Hello @Ga1ath and welcome to the SAS Support Communities!

 

I see two issues:

  1. A word boundary (PRX metacharacter \b) cannot occur directly after a comma or a period because by definition it is "the position between a word and a space" -- but neither the comma nor the period is a word character (cf. PRX metacharacter \w).
  2. The "\x" in your regular expression should read "|x".

Try this regex instead:

a=prxchange('s/\b(x\.,|x\.|x\b)//i', -1, name);
Ga1ath
Fluorite | Level 6

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?

FreelanceReinh
Jade | Level 19

@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);

Ga1ath
Fluorite | Level 6

Of course, yeah. I'm sorry for my inattention.

Tom
Super User Tom
Super User

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.

Ga1ath
Fluorite | Level 6

It is the wrong output. I'll edit the post.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 7406 views
  • 2 likes
  • 3 in conversation