PDA

View Full Version : Sum up values by groups



frapbois_tc
02-08-2010, 08:03 PM
date value
01.01.2008 9.9
01.01.2008 9.9
01.01.2008 12.9
01.01.2008 9.9
02.01.2008 12.9
02.01.2008 9.9
03.01.2008 12.9
. .
. .
. .
. .
. .

How can I sum up all the values for each day by sas?

why is it not possible to use " sumvalue+value; by date; "?

Many thanks
:)

fed1
02-08-2010, 08:51 PM
Try this

dm 'out; clear; log; clear;';

data test;
informat date mmddyy11.;
input date value 4.1;
format date date11.;
cards;
01.01.2008 9.9
01.01.2008 9.9
01.01.2008 12.9
01.01.2008 9.9
02.01.2008 12.9
02.01.2008 9.9
03.01.2008 12.9
;
run;


data test; set test; by date;
sumvalue + value;
if last.date then do;
output;
sumvalue = 0;
end;
run; quit;
proc print data = test; run; quit;

frapbois_tc
02-09-2010, 04:52 AM
hey thanks so much!
it has been really helpful to me!:)


i miss this step!!!!****if last.date then do; output;****

siftekhar
02-12-2010, 09:03 AM
for this kind of problem/procedure, I use Proc Summary with by and var options.

like this:

PROC SUMMARY data=dataset;
by date;
var value;
OUTPUT OUT=sum_dataset (drop=_type_ _freq_) SUM=;
run;