1
votes

I have a SAS macro variable that is:

&varlist. = OriginCd,DestinCd

I'm trying to get a new macro variable that is the same thing, but with the commas removed and a space. So this:

&newlist. = OriginCd DestinCd

I've tried the following:

%let newlist=%sysfunc(tranwrd(%sysfunc(compbl(&varlist)),%str(,),%str( )));
%let newlist = %sysfunc(compress(&varlist,','));
%let newlist = %sysfunc(tranwrd(&varlist,","," "));

For the tranward function, I get "the function TRANWRD referenced by %SYSFUNC macro function has too many arguments". But I'm pretty sure this is how you normally use it. Thanks!

1

1 Answers

2
votes

Try:

%let varlist=OriginCd,DestinCd;
%let newlist=%sysfunc(compbl(%sysfunc(tranwrd(%quote(&varlist),%str(,),%str( )))));
%put &=newlist;

I added %quote() to prevent the commas being interpreted as parameter delimeters, and switched the compbl() to the outside to prevent the need for another %quote()