k*****u 发帖数: 1688 | 1 options formdlim='-';
data test;
input ID seq unit;
cards;
100 1 10
100 2 10
101 1 10
101 1 20
103 1 10
103 2 10
104 1 10
104 1 20
;
run;
proc sort data=test;
by id seq;
run;
data want (keep=id seq sumunit);
set test;
by id seq;
if first.id or first.seq then sumunit=unit;
else sumunit+unit;
if last.id or last.seq then output;
run;
proc print data=want;
run; |
|
w*****8 发帖数: 395 | 2 data test;
input ID seq unit;
fakeID = id||'_'||seq;
cards;
100 1 10
100 2 10
101 1 10
101 1 20
103 1 10
103 2 10
104 1 10
104 1 20
;
run;
proc sort data=test;
by fakeID;
run;
data want (keep=id seq sumunit);
set test;
by fakeID;
if first.fakeID then sumunit=unit;
else sumunit+unit;
if last.id;
run;
proc print data=want;
run; |
|
w*****8 发帖数: 395 | 3 ....
data want (keep=id seq sumunit);
set test;
by fakeID;
if first.fakeID then sumunit=unit;
else sumunit+unit;
if last.id; <-- should be " if last.fakeID; "
run;
... |
|
w*****8 发帖数: 395 | 4 data test;
input ID seq unit;
cards;
100 1 10
100 2 10
101 1 10
101 1 20
103 1 10
103 2 10
104 1 10
104 1 20
;
run;
proc sort;by id seq;run;
proc means;
var unit;
by id seq;
output out=testSum sum=sumUnit;
run;
proc print data=testSum;run; |
|