tags:

views:

346

answers:

3

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?

+2  A: 

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 ;
    %test;

    %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 ;
    %test2
CarolinaJay65
+2  A: 

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 represneted by %str( ), as indicated above in Carolina post.

+1  A: 

you can use perl reg ex instead, like:

%put ***%sysfunc(prxchange(s/x/ /, -1, abxcdxxf))***;
/* on log
***ab cd  f***
*/
Chang Chung