DATA Step, Macro, Functions and more

function unknown

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

function unknown

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.


Accepted Solutions
Solution
‎08-24-2016 03:43 PM
Trusted Advisor
Posts: 1,378

Re: function unknown

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


All Replies
Super User
Super User
Posts: 7,401

Re: function unknown

[ Edited ]

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;
Solution
‎08-24-2016 03:43 PM
Trusted Advisor
Posts: 1,378

Re: function unknown

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;

Respected Advisor
Posts: 3,777

Re: function unknown

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 274 views
  • 5 likes
  • 4 in conversation