Try the code below, I believe it will give you what you want if I'm understanding your description correctly: data have; input raceA$ raceB$ raceP$ raceI$ raceW$; datalines; N N N N Y N N N Y N N N N Y Y N N Y N N N N Y N Y N Y N N N N Y N N Y N Y N Y Y Y N N N N Y N N N Y Y N Y N N Y Y N N N Y Y N N Y ; run; proc contents data=have noprint out=have_contents (keep=NAME); run; %macro race; data _NULL_; set have_contents end=lastobs; call symputx(cats('race',_n_),NAME); if lastobs then call symputx('n',_n_); run; data want; set have; combine=catx(',',raceA,raceB,raceP,raceI,raceW); If countc(combine,"Y")>1 then do; raceO="Y"; subgrp_race="raceO"; end; Else do; %do i=1 %to &n; If &&race&i="Y" then do; raceO="N"; subgrp_race="&&race&i"; end; %end; end; drop combine; run; %mend; %race Hope this helps!
... View more