sum in column by date

#1
Hi all,

I have a small problem which is holding me back and I cannot figure it out.

In a dataset I need to calculate the sum of variable "value" and put the result in a new variable "result".
The problem is, that the calculation needs to be done by id and date. Every id can have multiple dates. I want to sum up all values that occured for an id during one date.
Example: one id has 9 observations and 3 different dates. In variable "result" I want to have 3 entries, each in the last observation for every date (last.date) and it should hold the sum of "value" for each date.

So far I have this:


Code:
...
   retain result 0;
   do i = first.id to last.id;
      do j = first.date to last.date;
         result = sum(result, value);
      end;
   end;
...
That does calculates the sum, but over all observations in the dataset. It does not end at the last date for a patient and then starts again at the next date.

I hope you can help.
Thanks a lot!
Gingerfish
 
#2
Hi all,

I've solved it with a proc means.
Code:
proc means data=data1 sum;
   var value;
   by id date;
   output out = hlp1 sum = result;
run;
Thanks anyway!
Gingerfish