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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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