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 (January 2008, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 14 Jan 2008 09:02:49 -0600
Reply-To:     "data _null_," <datanull@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "data _null_," <datanull@GMAIL.COM>
Subject:      Re: cumulative sum with subgroups ?
Comments: To: Warren Schlechte <Warren.Schlechte@tpwd.state.tx.us>
In-Reply-To:  <43C07A163F7E764A8B27F6DAE2B126BF19D09702@tpwd-mx0.tpwd.state.tx.us>
Content-Type: text/plain; charset=ISO-8859-1

It is related to the use of sum statement.

x + 1;

same as

retain x 0; x = x + 1;

On Jan 14, 2008 8:56 AM, Warren Schlechte <Warren.Schlechte@tpwd.state.tx.us> wrote: > Interesting. > > I thought that without the retain, that cumsum would be set to a missing > value, since it doesn't exist within the dataset. Could someone explain > this to me? > > Thanks, > > Warren Schlechte > > -----Original Message----- > From: Hu, Jiangtang [mailto:jiangtanghu@gmail.com] > Sent: Saturday, January 12, 2008 2:30 AM > To: Warren Schlechte > Cc: SAS-L@listserv.uga.edu > Subject: Re: cumulative sum with subgroups ? > > A modified version of Warren's, delete "retain cumsum", > and replace "cumsum=sumnb+cumsum" with " cumsum+sumnb": > > data out; > set test; > by id; > if first.id then cumsum=sumnb; > else cumsum+sumnb; > run; > On Jan 12, 2008 1:15 AM, Warren Schlechte > <Warren.Schlechte@tpwd.state.tx.us > <mailto:Warren.Schlechte@tpwd.state.tx.us> > wrote: > data test; > input id date nnb sumnb; > datalines; > 1 10 2 15 > 1 11 1 15 > 1 12 1 20 > 1 13 1 10 > 2 7 1 150 > 2 9 1 200 > 2 10 2 150 > 2 17 1 300 > ; > run; > > proc sort data=test; by id;run; > > data out; > set test; > by id; > retain cumsum; > if first.id then cumsum=sumnb; else cumsum=sumnb+cumsum; > run; > > proc fsview data=out;run; > > Warren Schlechte > > > -----Original Message----- > > From: ChrisG [mailto:chris.godlewski@GMAIL.COM] > Sent: Friday, January 11, 2008 10:51 AM > Subject: cumulative sum with subgroups ? > > Hi > > Suppose i have such dataset : > > id date nnb sumnb > 1 10 2 15 > 1 11 1 15 > 1 12 1 20 > 1 13 1 10 > 2 7 1 150 > 2 9 1 200 > 2 10 2 150 > 2 17 1 300 > > i would like sas to do the following thing in a > additional variable, > let call it cumsumnb : > > id date nnb sumnb cumsumnb > 1 10 2 15 15 > 1 11 1 15 30 > 1 12 1 20 50 > 1 13 1 10 60 > 2 7 1 150 150 > 2 9 1 200 350 > 2 10 2 150 500 > 2 17 1 300 800 > > in other words, to calculate in an 'incremental way' the > cumulative > sum of sumnb by date within the id subgroup ... > > i hope i was clear enough ... > > many thanks for any help ! > > cheers > > CG > > > > -- > John Jiangtang Hu >


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