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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1120 views
  • 0 likes
  • 4 in conversation