我想知道是否有办法对多个类别进行频率调整,以便最终获得整体总记录,然后将子类别计算在其下面?
此刻你必须做2个频率然后2个转置,然后将数据设置在一起。以下是我通常会做到这一点的方法,但有没有办法在1个频率中完成?
Proc freq data = data noprint;
tables CATEGORY*SUBCATEGORY / out = Data1;
tables CATEGORY / out = Data2;
Run;
Proc sort data = DATA1 out = DATA1; by CATEGORY SUBCATEGORY; Run;
Proc sort data = DATA2 out = DATA2; by CATEGORY; Run;
Proc transpose data = DATA1 out = DATA1;
var COUNT;
by CATEGORY SUBCATEGORY;
Run;
Proc transpose data = DATA2 out = DATA2;
var COUNT;
by CATEGORY;
Run;
data Final;
set DATA1 DATA2;
run;
答案 0 :(得分:2)
使用PROC SUMMARY而不是FREQ,TYPES语句使您可以选择要汇总的组。这只需要一步。
proc summary data=data;
class CATEGORY SUBCATEGORY;
types CATEGORY CATEGORY*SUBCATEGORY;
output out=want(drop=_type_ rename=(_freq_=COUNT));
run;