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

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.

1 ACCEPTED SOLUTION
4 REPLIES 4
t_ar_taat
Quartz | Level 8

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;
novinosrin
Tourmaline | Level 20

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

t_ar_taat
Quartz | Level 8

Thank you so much,%str did work wellSmiley Happy

per_str.png

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