BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

Hi ,

I have dru-26-12345

           pru-26-56743

I want to change 26 to 34

dru-34-12345

pru-34-56743

 

please let me know.

thank you

5 REPLIES 5
Shmuel
Garnet | Level 18

option 1 - use tranwrd function,

option 2 - use prxchange function

as shown in next log output:

  

72         
 73         data _null_;
 74           txt = 'dru-26-12345';
 75           txt1 = prxchange('s/26/34/',-1,txt); put txt1=;
 76           txt2 = tranwrd(txt,'26','34'); put  txt2=;
 78         run;
 
 txt1=dru-34-12345
 txt2=dru-34-12345
Shmuel
Garnet | Level 18
The 's' in prxchange stands for 'substitute'/

'tranwrd' stands for translate word.
Ksharp
Super User
Better this.
prxchange('s/\b26\b/34/',-1,txt)
or
prxchange('s/-26-/-34-/',-1,txt)
otherwise , if txt1=dru-26-12326 , would get wrong result.
novinosrin
Tourmaline | Level 20

data have;
var='dru-26-12345';
output;
var='pru-26-56743';
output;
run;

data want;
 set have;
 var1=prxchange('s/([a-z]{3})-(26)-(\d{5})/$1-34-$3/i', -1, var);
run;
novinosrin
Tourmaline | Level 20

data have;
var='dru-26-12345';
output;
var='pru-26-56743';
output;
run;
data want;
 set have;
 if substr(var,5,2)='26' then substr(var,5,2)='34';
run;

/*OR*/
data want;
 set have;
 if scan(var,2,'-')='26' then substr(var,5,2)='34';
run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 768 views
  • 0 likes
  • 4 in conversation