%macro dlastwd( /* macro to delete the last word from a character variable. Usually edits in place. Requires v7 or later since it uses a negative index for the scan function. jgb, 4/2000 */ cvar, /*character variable whose value is to be edited */ cvarout=&cvar, /* character variable where edited result is stored */ keywords=, /* if value is specified then editing only occurs of last word is in this list */ dropvars=0, /* specify dropvars=1 to cause temporary vars used to be dropped. You must specify dropvars=1 once and only once within a single DATA step. */ dlms=%str( ,), /* default delimiters to use are just blanks and commas */ debug=0); _tempstr=&cvar; _tempwd=scan(_tempstr,2,"&dlms"); %if &debug %then %str(put _tempwd=;); if _tempwd ne " " then do _tempidx = 1 to 1; *--without index cannot use leave stmt-; _lastwd=scan(trim(_tempstr),-1,"&dlms"); %if &debug %then %str(put _lastwd=;); %if %quote(&keywords) ne %then %do ; if indexw ("&keywords",_lastwd) =0 then leave; %end; &cvarout=substr(&cvar,1, length(&cvar)-length(_lastwd)-1); end; %if &dropvars %then %str( drop _tempstr _tempwd _lastwd _tempidx;); %mend dlastwd;