LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 8 Jul 2004 03:28:08 -0700
Reply-To:     Guido <cymraeg_erict@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Guido <cymraeg_erict@HOTMAIL.COM>
Organization: http://groups.google.com
Subject:      R e: Easy data step question
Content-Type: text/plain; charset=ISO-8859-1

Hi Ben,

I expect I've got what you want wrong ... but try :-

data sum; set test; sumapp+apples; run;

SUMAPP is implicity retained and initialised to zero though the use of sum statement. Personally I would use :-

data sum; set test; retain sumapp 0; sumapp = sumapp+apples; run;

just to make it obvious to other people what is going on. But you could use something more interesting like a DoW loop :-

data sum; do until (eof); set test end=eof; sumapp+apples; output; end; run;

HTH

Guido

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of ben.powell@CLA.CO.UK Sent: Thursday, July 08, 2004 11:03 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Easy data step question

Dear SAS-L

What is the best way to create a sum variable in a dataset - apologies in advance for brain thinking in terms of Excel - without using proc summary or proc freq? E.g. for variable apples in dataset a, how do I create variable sum_of_apples which for

(_N_ = 1) = apples_1

and for

(_N_ = 2) = apples_1 + apples_2 ... (_N_ = n) = apples_1 + ... + apples_n

this being the same as

(where n ^ = 1) sum_of_apples_n = sum_of_apples_(n-1) + apples_n

Sorry to insult your intelligence! I'm trying to disguise my own lack of *same* by using the word *best* to obscure the fact I don't have *any* :-)

Thanks,

Ben.


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