Date: Sat, 2 Jul 2005 04:58:29 -0700
Reply-To: Dorian <d.noel@ISMACENTRE.RDG.AC.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Dorian <d.noel@ISMACENTRE.RDG.AC.UK>
Organization: http://groups.google.com
Subject: Re: sum in a Data step
Content-Type: text/plain; charset="iso-8859-1"
You can try this as well. The DoW at its very best!!!
data myds;
input A B cost;
cards;
1 2 5.00
1 2 4.00
2 2 3.00
2 2 2.00
2 3 1.00
;
run;
proc sort;
by a b;
run;
data total;
do total = 0 by 0 until(last.b);
set myds;
by a b;
total + cost;
end;
do until (last.b);
set myds;
by a b;
output;
end;
run;
gscsrc@hotmail.com wrote:
> How do I sum using two fields in a data step? Using A and B
>
> sample data:
>
> fields A B cost
> 1 2 5.00
> 1 2 4.00
> 2 2 3.00
> 2 2 2.00
> 2 3 1.00
>
> I believe I need to use something like
> SumCost = sum(cost)
>
> looking for results:
>
> fields A B cost SumCost
> 1 2 5.00 9.00
> 1 2 4.00 9.00
> 2 2 3.00 5.00
> 2 2 2.00 5.00
> 2 3 1.00 1.00
> Do I need to sort A and B and whatelse do I need to put in
> the data step?
>
> Thanks!