LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (July 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
Comments: To: sas-l@uga.edu
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!


Back to: Top of message | Previous page | Main SAS-L page