Art,
Thanks for pointing out a couple of holes in my code. Your solution is slick and provided yet another way to utilize arrays.
Just for the sake of closure, I have modified my code to address the multiple words as body parts.
data query (keep= id visit _part rename=(_part=body_part));
set ink;
by id visit body_part;
length cumul_body_parts parts_curvis $100;
retain cumul_body_parts parts_curvis '';
if first.id then cumul_body_parts = '';
if first.visit then parts_curvis = '';
if index(cumul_body_parts, strip(body_part))=0 then cumul_body_parts = catx(', ',cumul_body_parts,body_part);
if index(parts_curvis, strip(body_part))=0 then parts_curvis = catx(', ',parts_curvis,body_part);
if last.visit then do i=1 to countw(cumul_body_parts,',');
x = strip(scan(cumul_body_parts, i, ','));
if index(parts_curvis, strip(scan(cumul_body_parts, i, ',')))=0 then do;
_part = strip(scan(cumul_body_parts, i, ','));
output;
end;
end;
run;
... View more