/*----- * group: Macro programming * purpose: Returns the last word from a delimited list of words.
Version 8: use %scan (x y z, -1) * notes: Useful for some generic forms of DATA Step BY processing with first. and last. logic */ %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;