DATA Step, Macro, Functions and more

Substitute Characters in a Defined String

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 79
Accepted Solution

Substitute Characters in a Defined String

Let's say I define

%let person=John James Doe

 

How do I substitue the spaces with underscores, so I get the following effect, without typing the person's name?

%let person=John_James_Doe;

 

Thanks.


Accepted Solutions
Solution
‎08-14-2017 05:09 PM
SAS Super FREQ
Posts: 496

Re: Substitute Characters in a Defined String

Posted in reply to apolitical

 

%let person=John James Doe;
%let person = %sysfunc(tranwrd(&person,%str( ), _));
%put &person;

View solution in original post


All Replies
Solution
‎08-14-2017 05:09 PM
SAS Super FREQ
Posts: 496

Re: Substitute Characters in a Defined String

Posted in reply to apolitical

 

%let person=John James Doe;
%let person = %sysfunc(tranwrd(&person,%str( ), _));
%put &person;
Frequent Contributor
Posts: 79

Re: Substitute Characters in a Defined String

Posted in reply to WarrenKuhfeld

works like a charm. thank you!

Super Contributor
Posts: 478

Re: Substitute Characters in a Defined String

Posted in reply to apolitical

Hi,

 

If your trying to substitute the values in the data step when calling the macro something like this works.

 

%let person=John James Doe;
DATA test;
person=TRANWRD("&person"," ","_");
RUN;

Thanks,
Suryakiran
Frequent Contributor
Posts: 79

Re: Substitute Characters in a Defined String

Posted in reply to SuryaKiran
yeah i tried that and also transtrn and translate functions, turns out what i need is a %sysfunc in the front. thank you.
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 250 views
  • 0 likes
  • 3 in conversation