- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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(" ")));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes, quotes aren't required in macro functions so you need to mask the string in another way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.