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.
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!
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.