SQL can count distinct combinations by concatenating the combination parts with a delimiter. The delimiter ensures distinct combinations.
Example:
proc sql;
create table want as
select
teacher_id
, count (distinct catx('~',smtt,teacher_id,class_id)) as Nclass
, count (x) as Nstudents
from have
group by teacher_id
;
You can also do serial processing in DATA Step using nested DOW loops
proc sort data=have;
by teacher_id smtt class_id;
run;
data want;
length teacher_id $8;
do Nclass = sum(Nclass,1) by 1 until (last.teacher_id);
do Nstudents = sum(Nstudents,1) by 1 until (last.class_id);
set have;
by teacher_id smtt class_id;
end;
end;
keep teacher_id Nclass Nstudents;
run;
... View more