DATA Step, Macro, Functions and more

Leave space(eq Don't compress) after replacement(tranwrd and %sysfunc) in MACRO

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

Leave space(eq Don't compress) after replacement(tranwrd and %sysfunc) in MACRO

Hi,all

I want change macro variable's value "t-1-1" to "Table 1-1",say,"Table" + space + "1-1"
So I try #1

%let pow=t-1-1;
%let x = %sysfunc(tranwrd(&pow,t,Table ));
%put x=&x;

The %put statement returns "x=Table-1-1"
but I want "x=Table -1-1",which containing space.

 

Other way I tried is

%let x2 = %sysfunc(tranwrd(&pow,t,%quote(Table ));

but this resulted in ERROR and can't make macro variable.

Please help me!  XD

Sincerely.


Accepted Solutions
Solution
‎04-30-2017 06:35 AM
Super User
Posts: 7,771

Re: Leave space(eq Don't compress) after replacement(tranwrd and %sysfunc) in MACRO

Posted in reply to t_ar_taat

Build the string in a data _null_ step and use call symput. In a data step

tranwrd("&pow","t","Table ")

should work.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎04-30-2017 06:35 AM
Super User
Posts: 7,771

Re: Leave space(eq Don't compress) after replacement(tranwrd and %sysfunc) in MACRO

Posted in reply to t_ar_taat

Build the string in a data _null_ step and use call symput. In a data step

tranwrd("&pow","t","Table ")

should work.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 35

Re: Leave space(eq Don't compress) after replacement(tranwrd and %sysfunc) in MACRO

Posted in reply to KurtBremser

Thank you so much Kurt,your knowledge work so nice.

%let pow=t-1-1;
data _null_;
 call symput("x",tranwrd("&pow","t","Table "));
run;
%put x is &x;
PROC Star
Posts: 283

Re: Leave space(eq Don't compress) after replacement(tranwrd and %sysfunc) in MACRO

Posted in reply to t_ar_taat

Your second one does work-->

 

%let x2 = %sysfunc(tranwrd(&pow,t,%quote(Table )));/*add another closing parenthesis*/

%put x=&x2;

 

I will not recommend using macro execution functions such as quote or bquote and its NR mate in quoting constant text, I'd rather use %str as it is powerful to quote at the time of macro compilation. 

 

%let x2 = %sysfunc(tranwrd(&pow,t,%str(Table )));
%put x=&x2;

 

Regards,

Naveen Srinivasan

Contributor
Posts: 35

Re: Leave space(eq Don't compress) after replacement(tranwrd and %sysfunc) in MACRO

Posted in reply to novinosrin

Thank you so much,%str did work wellSmiley Happy

per_str.png

☑ This topic is solved.

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

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