Hi, I am wondering how to edit macro list to add suffix to all of its items. Let's say I have %let vars=one_ two_ three_; I would like to make a macro that loops several times (10x) and in each loop it adds different suffix to &vars. I came accross SAS list string utils from Jiangtang Hu - List Processing with SAS: A Comprehensive Survey and I used edited version of his %add_string macro: %macro add_string(words, str, delim=%str( ), location=suffix);
%local outstr i word num_words;
* Build the outstr by looping through the words list and adding the
* requested string onto each word. ;
%let outstr = ;
%let num_words = %sysfunc(countw(&words));
%do i=1 %to &num_words;
%let word = %scan(&words, &i, &delim);
%if (&i eq 1) %then %do;
%if (%upcase(&location) eq PREFIX) %then %do;
%let outstr = &str&word;
%end;
%else %do;
%let outstr = &word&str;
%end;
%end;
%else %do;
%if (%upcase(&location) eq PREFIX) %then %do;
%let outstr = &outstr&delim&str&word;
%end;
%else %do;
%let outstr = &outstr&delim&word&str;
%end;
%end;
%end;
* Output the new list of words. ;
&outstr
%mend add_string; The problem is how to handle the output from such a macro? When I call it I get an Error : Statement is no valid: %let vars=one_ two_ three_;
%let vars1r=%add_string(&vars, 1r); "ERROR 180-322: STATEMENT IS NOT VALID OR IT IS USED OUT OF PROPER ORDER." the problem is causing &outstr in macro definition, but I don't know how to output from macro in other way. (I am working with SAS enterprise guide 9.4) Any suggestions? Thanks...
... View more