|
5#
楼主 |
发表于 2004-4-24 20:33:26
|
只看该作者
[quote="yooyork":fd37b]proc summary data=score;
by id;
var score;
output out=totscore sum=totscore;
run;
proc summary data=score;
by id subject;
var score;
output out=subjectscore sum=subjectscore;
run;
proc sql;
create table totscore as select id, sum(score) as totscore from score
group by id;
create table subjectscore as select id, subject, sum(score) as subjectscore from score
group by id, subject;[/quote:fd37b]
其实一个proc summary过程就可以算出:
proc summary data=score;
class id subject;
types id id*subject;
output out=totscore sum=score;
run;
结果集totscore中_type_=2的是根据id的总分,_type_=3的是根据id和subject的科目总分。
提示:一个过程算出多种汇总层次的结果是SAS Proc Means/Summary的优势之一,特别是它具有优化的汇总顺序
首先汇总id+subject,然后根据id+subject的结果去汇总id,而不是直接汇总id,所以效率很高。_type_是区分汇总层次的变量,对于结果拆分很有用。
而数据库系的SQL到了SQL 99 才有类似的cube语句出现。 |
|