I have a data set :
data data;
input group $ count;
datalines;
A 4
A 3
A 2
A 1
B 1
C 1
D 2
D 1
E 1
F 1
G 2
G 1
H 1
;
run;
The first variable is a group identifier, the second count the number of observations by group, the dataset is sorted by group and then by count in descending order.
I want a new variable that take the max of "count" variable for each group such as :
data data;
input group $ count max_count;
datalines;
A 4 4
A 3 4
A 2 4
A 1 4
B 1 1
C 1 1
D 2 2
D 1 2
E 1 1
F 1 1
G 2 2
G 1 2
H 1 1
;
run;
The closest I've managed to get is by doing :
data data;
set data;
by group;
if first.group then max_count=count;
run;
But the result is :
data data;
input group $ count max_count;
datalines;
A 4 4
A 3 .
A 2 .
A 1 .
B 1 1
C 1 1
D 2 2
D 1 .
E 1 1
F 1 1
G 2 2
G 1 .
H 1 1
;
run;
Any idea how to perform this please?