PDA

View Full Version : summing up values by groups

devilfinn
02-16-2010, 09:24 AM
hello,

i have a problem...

i have a dataset containing dates, positive transfers and negative transfers. aproximately 1 000 000 observations spanning 1 year as this:

time dd.mm.yy
11:00 01.01.09 +1 -
12:00 01.01.09 +5 -
13:00 01.01.09 - +9
14:00 01.01.09 +1 -
16:30 01.01.09 - +8
09:30 02.01.09 +1 -
12:00 02.01.09 - +3
13:00 02.01.09 - +4
13:03 02.01.09 +11 -

My question is if it is possible to sort the data so i can get it summed on a daily basis. The sum of all postive transfers - all negative transfers on a daily basis, so i would get a new collumn called ex. sum, that would give me this output:

date: sum:
01.01.09 -10
02.01.09 +5
03.01.09 ***x

thanks for any help

finn
devilfinn is online now Add to devilfinn's Reputation Report Post Edit/Delete Message

fed1
02-16-2010, 01:13 PM
ata devilfinn;
infile cards dsd missover dlm = ' ';
input time : time10. date : ddmmyy20. xfer1 xfer2;
if xfer1 = . then xfer1 = 0;
if xfer2 = . then xfer2 = 0;
xfer = xfer1 + xfer2;
day = day(date);
format time time6. date ddmmyy10.;
cards;
11:00 01.01.09 +1 -
12:00 01.01.09 +5 -
13:00 01.01.09 - +9
14:00 01.01.09 +1 -
16:30 01.01.09 - +8
09:30 02.01.09 +1 -
12:00 02.01.09 - +3
13:00 02.01.09 - +4
13:03 02.01.09 +11 -
;
run;

data daily(drop = xfer day); set devilfinn;
by day;
total + xfer;
if last.day then do;
output; total = 0;
end;
run;

proc print data = devilfinn; run; quit;
proc print data = daily; run; quit;