BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASuserlot
Barite | Level 11

I am looking to create macro variable which contains the list of variables from the dataset. I am going to use the same list in different places of my big macro.  My requirement is , I want to replace the  'comma' (,) symbol with a one blank space where ever needed. I tried the  ' TRANWRD' along with the "%sysfunc" . Unfortunately I can not get the output I am expected. Thank you for your suggestions.

%let havelist= %str(company,month,expenses,adjustment,balance);

%let wantlist = %sysfunc(tranwrd(&havelist,","," "));

* looking &wantlist display as 'company month expenses adjustment balance';

%put &havelist ;
%put &wantlist

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
%let havelist= %str(company,month,expenses,adjustment,balance);

%let wantlist = %sysfunc(tranwrd(&havelist,%str(,),%str( )));

* looking &wantlist display as 'company month expenses adjustment balance';

%put &havelist ;
%put &wantlist;

View solution in original post

6 REPLIES 6
Reeza
Super User
%let havelist= %str(company,month,expenses,adjustment,balance);

%let wantlist = %sysfunc(tranwrd(&havelist,%str(,),%str( )));

* looking &wantlist display as 'company month expenses adjustment balance';

%put &havelist ;
%put &wantlist;
SASuserlot
Barite | Level 11

It worked. thank you @Reeza @Kc2 .  %str making the difference? we need to use the '%str' in these scenarios?  how to use if there is double space needed instead of single space? Can I use like below double space between double quotes in the second %str option.

%let wantlist = %sysfunc(tranwrd(&havelist,%str(,),%str("  ")));

Reeza
Super User

Yes, quotes aren't required in macro functions so you need to mask the string in another way. 

 

 

Kc2
Quartz | Level 8 Kc2
Quartz | Level 8

try this code;

%let havelist= %str(company,month,expenses,adjustment,balance);

%let wantlist = %sysfunc(tranwrd(%quote(&havelist),%str(,),%str( )));

* looking &wantlist display as 'company month expenses adjustment balance';

%put &havelist ;
%put &wantlist;

Tom
Super User Tom
Super User

@SASuserlot wrote:

I am looking to create macro variable which contains the list of variables from the dataset. I am going to use the same list in different places of my big macro.  My requirement is , I want to replace the  'comma' (,) symbol with a one blank space where ever needed. I tried the  ' TRANWRD' along with the "%sysfunc" . Unfortunately I can not get the output I am expected. Thank you for your suggestions.

%let havelist= %str(company,month,expenses,adjustment,balance);
%let wantlist = %sysfunc(tranwrd(&havelist,","," "));

* looking &wantlist display as 'company month expenses adjustment balance';

There are NOT any commas enclosed in double quote characters in &HAVELIST, so the TRANWRD() function will just return the original value.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 4730 views
  • 3 likes
  • 4 in conversation