Sub-query the data first:
proc sql;
create table WANT_SUM as
select YR,
MNTH,
sum(TOTALAMOUNT) as TOT
from (select year(datepart(ORDERDATE)) as YR, month(datepart(ORDERDATE)) as MNTH, TOTALAMOUNT from HAVE where calculated YR=2008)
group by YR,MNTH;
quit;
You could also do it using a "having" clause, though I prefer the sub-query. You can also do it in datastep:
data inter;
set have (where=(year(datepart(orderdate))=2008);
yr=2008;
mnth=month(datepart(orderdate));
run;
data want;
set inter;
by mnth;
retain tot;
tot=ifn(first.mnth,0,tot+totalamount); run;
... View more