Take the 2-minute tour ×

In SAS, outside of a data step, what is the best way to replace a character in a macro variable with a blank?

It seems that TRANSLATE would be a good function to use. However when using %SYSFUNC with this function, the parameters are not surrounded with quotes. How do you indicate a blank should be used as replacement?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

There are no quotes in macro language. The only quotes characters that are in use are the & , % etc. to indicate that the text should be interpreted as a macro "operator". A blank is represented by %str( ) as indicated above in Carolina's post.

share|improve this answer

The %str( ) (with a blank between the parens) can be used to indicate a blank for this parameter. Also be careful with TRANSLATE...the 2nd param is the replacement char...however in TRANWRD it is reversed.

    %macro test ;
	 %let original= translate_this_var ;
	 %let replaceWithThis= %str( ) ;
     %let findThis= _ ;
     %let translated= %sysfunc(translate(&original, &replaceWithThis, &findThis)) ;
     %put Original: &original ***** TRANSLATEd: &translated ;
    %mend ;

    %macro test2 ;
  	 %let original= translate_this_var ;
	 %let replaceWithThis= %str( ) ;
     %let findThis= _ ;
     %let tranwrded= %sysfunc(tranwrd(&original, &findThis, &replaceWithThis)) ;
     %put Original: &original ***** TRANWRDed: &tranwrded ;
    %mend ;
share|improve this answer

you can use perl reg ex instead, like:

%put ***%sysfunc(prxchange(s/x/ /, -1, abxcdxxf))***;
/* on log
***ab cd  f***
share|improve this answer

Your Answer


