BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RajasekharReddy
Fluorite | Level 6

 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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
HB
Barite | Level 11 HB
Barite | Level 11

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

5 REPLIES 5
HB
Barite | Level 11 HB
Barite | Level 11

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

 

kiranv_
Rhodochrosite | Level 12

something like this

data _null_;
   x = 'MCLAUREN';
   y = prxchange("s/^(MC)(.+)/Mc$2/i", -1, x);
   put y=;
run;
jim_cai
Calcite | Level 5
or something like prxchange("s/^MC(.+)/Mc$1/", -1, x), since "Mc" is typed in manually so it is unnecessary to catch "MC".
Patrick
Opal | Level 21

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
Ksharp
Super User
data _null_;
   x = 'MCLAUREN';
   y = prxchange("s/^(MC)/\u\L$1/i", 1, x);
   put y=;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 5 replies
  • 885 views
  • 1 like
  • 6 in conversation