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 (August 2009, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 13 Aug 2009 10:26:54 -0700
Reply-To:     "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Subject:      Re: conditional cumulative sum
Comments: To: Amy <amyzyj92@GMAIL.COM>
In-Reply-To:  A<b41df43f-bb20-4d17-804e-5e67b2957f93@x5g2000prf.googlegroups.com>
Content-Type: text/plain; charset="us-ascii"

Hi Amy,

Nat's code does that correctly for you. He has the "b" variable in the sample dataset just to show you that the new independent calculation of "newb" does do what you want. So just pretend the "b" is not there and pretend that "newb" is the "b" you are after. You certainly can adjust the code to match.

data test; input a; cards; 1 0 0 1 1 0 0 0 1 1 1 ; run; Data test; set test; if a ne 0 then b + 1;* this does a cumulative sum; else b = 0; run; proc print; run;

Hope this is helpful.

Mark Terjeson Investment Business Intelligence Investment Management & Research Russell Investments 253-439-2367

Russell Global Leaders in Multi-Manager Investing

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Amy Sent: Thursday, August 13, 2009 10:09 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: conditional cumulative sum

sorry, I think I did not make it clear enough.

the only data in the file is the variable called a, data under b variable is the result I want to get use some programming. thanks.

On Aug 13, 12:03 pm, nathaniel.wood...@DOM.COM (Nathaniel Wooding) wrote: > Amy > > Take a look at the following > > data test; > input a b; > cards; > 1 1 > 0 0 > 0 0 > 1 1 > 1 2 > 0 0 > 0 0 > 0 0 > 1 1 > 1 2 > 1 3 > > ; > run; > Data test; > set test; > if a ne 0 then newb + 1;* this does a cumulative sum; > else newb = 0; > run; > proc print; > run; > > Nat Wooding > > > > -----Original Message----- > From: SAS(r) Discussion [mailto:SA...@LISTSERV.UGA.EDU] On Behalf Of Amy > Sent: Thursday, August 13, 2009 11:56 AM > To: SA...@LISTSERV.UGA.EDU > Subject: conditional cumulative sum > > hey, > > my data is look like this: > > a b > 1 1 > 0 0 > 0 0 > 1 1 > 1 2 > 0 0 > 0 0 > 0 0 > 1 1 > 1 2 > 1 3 > a is the original number, and b is the cumulative sum when a is not 0. > > can anyone help me to figure this out? > > thank you! > CONFIDENTIALITY NOTICE: This electronic message contains > information which may be legally confidential and or privileged and > does not in any case represent a firm ENERGY COMMODITY bid or offer > relating thereto which binds the sender without an additional > express written confirmation to that effect. The information is > intended solely for the individual or entity named above and access > by anyone else is unauthorized. If you are not the intended > recipient, any disclosure, copying, distribution, or use of the > contents of this information is prohibited and may be unlawful. If > you have received this electronic transmission in error, please > reply immediately to the sender that you have received the message > in error, and delete it. Thank you.- Hide quoted text - > > - Show quoted text -


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