proc sql;
create table wanted as
select grou, sum(a='y') as a1, sum(b='y') as b1, sum(c='y') as c1
from tt
group by grou;
quit;
用data步也比较方便:
proc sort data=tt;
by grou;
run;
data wanted;
set tt;
by grou;
if first.grou then do;
a1=0;b1=0;c1=0;
end;
if a='y' then a1+1;
if b='y' then b1+1;
if c='y' then c1+1;
if last.grou;
keep grou a1 b1 c1;
run;
proc sql;
create table mm as
select grou,
sum(case a when 'y' then 1 else 0) as a1,
sum(case b when 'y' then 1 else 0) as b1,
sum(case b when 'y' then 1 else 0) as c1
from tt
group by grou;
quit;