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
%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;
%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;
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(" ")));
Yes, quotes aren't required in macro functions so you need to mask the string in another way.
Thank you.
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;
@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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.