DATA Step, Macro, Functions and more

Perl expression

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

Perl expression

 Hello ,

 

Please help to change "MCLAUREN" value as "McLAUREN"  by using Perl Expression (PRXCHANGE)

 

I tried below code but didn't work for me

 

data _null_;
   x = 'MCLAUREN';
   y = prxchange("s/ (MC) /\u\L$1/i", -1, x);
   put y=;
run;

 

Thanks in Advance

 

 


Accepted Solutions
Solution
3 weeks ago
Super Contributor
Super Contributor
Posts: 266

Re: Perl expression

Posted in reply to RajasekharReddy

Look at the example on Page 9 of this:

 

http://www2.sas.com/proceedings/forum2007/223-2007.pdf

 

I think you want to set your regular expression first like

re = prxparse('s/ (MC) /\u\L$1/i');

 

and then call it like they do 

 

cleanname= prxchange( re, 1, oldname);

 

View solution in original post


All Replies
Solution
3 weeks ago
Super Contributor
Super Contributor
Posts: 266

Re: Perl expression

Posted in reply to RajasekharReddy

Look at the example on Page 9 of this:

 

http://www2.sas.com/proceedings/forum2007/223-2007.pdf

 

I think you want to set your regular expression first like

re = prxparse('s/ (MC) /\u\L$1/i');

 

and then call it like they do 

 

cleanname= prxchange( re, 1, oldname);

 

PROC Star
Posts: 504

Re: Perl expression

Posted in reply to RajasekharReddy

something like this

data _null_;
   x = 'MCLAUREN';
   y = prxchange("s/^(MC)(.+)/Mc$2/i", -1, x);
   put y=;
run;
Occasional Contributor
Posts: 7

Re: Perl expression

or something like prxchange("s/^MC(.+)/Mc$1/", -1, x), since "Mc" is typed in manually so it is unnecessary to catch "MC".
Respected Advisor
Posts: 4,702

Re: Perl expression

[ Edited ]
Posted in reply to RajasekharReddy

Or like this:

data _null_;
   x = 'pEter MClAUREN & ian macIllIoMChadha';
   y = prxchange("s/\b(MC|MAC)(\w)/\1\u\2/i", -1, propcase(x));
   put y=;
run;

Result:

y=Peter McLauren & Ian MacIlliomchadha
Super User
Posts: 10,700

Re: Perl expression

Posted in reply to RajasekharReddy
data _null_;
   x = 'MCLAUREN';
   y = prxchange("s/^(MC)/\u\L$1/i", 1, x);
   put y=;
run;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 113 views
  • 1 like
  • 6 in conversation