data out(keep=id totalscore);
set tmp;
by id;
if first.id then totalscore=0;
totalscore+subject;
if last.id then output;
run;
至于合并
proc sort data=tmp;
by id subject;
data tmp1(drop=score rename=(subscore=score));
set tmp;
by id subject;
if first.subject then subscore=0;
subscore+score;
if last.subject then output;
run;作者: shiyiming 时间: 2004-4-19 19:21
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;作者: shiyiming 时间: 2004-4-23 16:51 标题: 感谢 本来想偷懒不顶了,后来看了别的论坛一个斑竹的帖子提到提问的人都是不劳而获,应该回贴表示感谢,同时也是对别人劳动成果的尊重,觉得很有道理。
多谢各位高手的讲解 <!-- s:lol: --><img src="{SMILIES_PATH}/icon_lol.gif" alt=":lol:" title="Laughing" /><!-- s:lol: -->作者: shiyiming 时间: 2004-4-24 20:33
[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;