由买买提看人间百态

topics

全部话题 - 话题: sumcc
(共0页)
t********m
发帖数: 939
1
data test;
input id cc;
cards;
1 1
1 1
2 2
2 2
2 2
;
run;
proc sort data=test;
by id;
run;
我想得到的data如下:
id cc sumcc
1 1 2
1 1 2
2 2 3
2 2 3
2 2 3
也就是说我想统计每个id有多少行数据并将那个值赋给sumcc,最后打印出id的每个
record但是要包含sumcc这个变量。
看着挺简单,可一时搞不出来。请教各位大侠了,多谢多谢!
G********L
发帖数: 12
2
data newtest;
set test;
by id;
if first.id then sumcc=0;
sumcc+1;
if last.id;
run;
data test;
merge test newtest;
by id;
run;
n*****n
发帖数: 3123
3
data test;
input id cc;
cards;
1 1
1 1
2 2
2 2
2 2
;
run;
proc sort test;
by id;
run;
proc freq data=test;
table id / out=counts;
run;
data test;
merge test counts(keep = id count rename=(count=sumcc));
by id;
run;
x********i
发帖数: 1
4
根本不用merge的,下面程序就可以满足你要求了:
data test;
input id cc;
cards;
1 1
1 1
2 2
2 2
2 2
;
run;
***********my code;
proc sql;
create table test2 as
select *, count(id) as sumcc
from test
group by id;
run;
(共0页)