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

Hi everybody,

 

is there a function for following problem:

 

I have a string like "abc,def." and I want replace "," and "."  with numbers or characters. I just want use the function once. 

 

Regards,

 

Cons.

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

You cam do both replacement at same time by:

new_text = translate(old_text,'12',',.');

 

argument for translate are: input string, replace into chracters, repce from characters.

the order of chracters should fit;

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

The function you are looking for is tranwrd():

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000215027.htm

 

A search for string functions will yield you many different types of string processing functions.

Example:

data want;
  text="abc,def.";
  /* replace comma with 1 */
  new_text=tranwrd(text,",","1");
  /* replace dot with A */
  new_text=tranwrd(new_text,".","A");
run;
Shmuel
Garnet | Level 18

You cam do both replacement at same time by:

new_text = translate(old_text,'12',',.');

 

argument for translate are: input string, replace into chracters, repce from characters.

the order of chracters should fit;

data_null__
Jade | Level 19

You are correct translate is the preferred function to use when changing single characters.

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
  • 3 replies
  • 1498 views
  • 5 likes
  • 4 in conversation