Download lastword.sas lastword.sasSubmit a comment

%macro lastword(words, sep=%str( ));

%* Richard A. DeVenezia - 940729
%*
%* extract last word from list of words separated by a specified character
%*
%* words  - original list of words, separated with something
%*;

  %local N W;

  %let N=1;
  %let W=%scan(&words,&N,%quote(&sep));

  %let N=2;
  %do %while (%scan(&words,&N,%quote(&sep))^=);
    %let W=%scan(&words,&N,%quote(&sep));

    %let N=%eval(&N+1);
  %end;

  &W

%mend;