data WANT; set HAE; length GROUP $50; re=prxparse('s/REF/""/'); POS=prxmatch(RE,DESC); if POS=0 then do; re=prxparse('s/CAT/""/'); POS=prxmatch(RE,DESC); if POS=0 then do; re=prxparse('s/sP/""/'); POS=prxmatch(RE,DESC); end; end; GROUP=sbsustr(DESC,sum(POS,-1)); if scan(GROUP,-1,"")='P' then GROUP=substr(GROUP,1,length(GROUP)-1); run; I bet some contributors can help and make this code even better. But it does the work, for now.
... View more