Adding grouped variable without rejoining

I have two datasets. One has ID number and several categorical variables, like this:

ID cat_var1 cat_var2 cat_var3

1 a d i

2 b f h

3 c e j

4 a e h

5 c d h

Dataset 1 is unique at the ID level. Dataset 2 has an ID variable; a numeric variable, which always equals 1; and a group variable. Each ID recurs several times in Dataset 2, like this:

ID count_var group_var

1 1 1

1 1 1

1 1 2

1 1 2

1 1 2

2 1 1

2 1 1

2 1 1

What I want is to sum the count_var by ID and group (that is, ID=1 would have sum=2 for group 1 and sum=3 for group 2) and add the sum variables to Dataset 1. I know the inefficient way to do this--do a proc sql sum of count_var grouping by ID and group_var, then transpose, then join to Dataset 1 on ID--but I'm hoping there's a more efficient way to get what I want.