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

Using prxchange, how can I replace the : in the below string with a space. This is only an example of the string, so to make it as dynamic as possible please. i.e. the string may not be in this exact order, or it may be longer/shorter.  I only want to remove the colon between 3Sbvx6822:Mcnt8969, and leave the rest. 

have: {"var1":"0","var2":"3Sbvx6822:Mcnt8969","var3":"0","var4":"0","var5":"0"}

 

want: {"var1":"0","var2":"3Sbvx6822 Mcnt8969","var3":"0","var4":"0","var5":"0"}

 

using the below code partially worked, but removed 3Sbvx6822: rather than just the :

prxchange('s/(\w+:)//oi', -1,trim(keyvaluepairs)) 

 

Any help is appreciated.

 

Cheers. 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @94seanhogan and welcome to the SAS Support Communities (as a first-time poster)!

 

You could replace a string of word characters followed by a colon with that same string followed by a space:

want=prxchange('s/(\w+):/$1 /',-1,keyvaluepairs);

Or replace a colon, if preceded by a word character, with a space:

want=prxchange('s/(?<=\w):/ /',-1,keyvaluepairs);

View solution in original post

1 REPLY 1
FreelanceReinh
Jade | Level 19

Hello @94seanhogan and welcome to the SAS Support Communities (as a first-time poster)!

 

You could replace a string of word characters followed by a colon with that same string followed by a space:

want=prxchange('s/(\w+):/$1 /',-1,keyvaluepairs);

Or replace a colon, if preceded by a word character, with a space:

want=prxchange('s/(?<=\w):/ /',-1,keyvaluepairs);

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 738 views
  • 3 likes
  • 2 in conversation