```Date: Mon, 21 Jan 2008 12:03:36 -0600 Reply-To: "data _null_," Sender: "SAS(r) Discussion" From: "data _null_," Subject: Re: Cummulative sum other subgroup Comments: To: Muthia Kachirayan In-Reply-To: <2fc7f3340801210938s53f50fccn705772065dac2e9f@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 using SUM function you can dispense with the IF statement and take advantage of DO UNTIL LAST this capturing the problem rhythm. cc = sum(cc,ct); On Jan 21, 2008 11:38 AM, Muthia Kachirayan wrote: > Djassy, > > Here is a way. > > data test ; > input an mo de ct; > datalines; > 1 1 1 5 > 1 1 2 7 > 1 1 3 6 > 1 2 1 8 > 1 2 2 3 > 2 1 1 9 > 2 1 2 6 > 2 2 1 4 > ; > run; > proc sort data = test; > by an mo; > run; > > data wanted; > do until(last.mo); > set test; > by an mo; > if first.mo then cc = 0; > cc ++ ct; > output; > end; > run; > > proc print; > run; > > > regards, > > Muthia Kachirayan > > > On Jan 21, 2008 11:57 AM, wrote: > > > Is there someone to help me? > > I would like to calculate cc as cumulative sum of ct, group by an, mo, > > de > > > > > > an mo de cc ct > > 1 1 1 5 5 > > 1 1 2 7 12 > > 1 1 3 6 18 > > 1 2 1 8 8 > > 1 2 2 3 11 > > 2 1 1 9 9 > > 2 1 2 6 15 > > 2 2 1 4 4 > > > > data test ; > > input an mo de ct; > > datalines; > > 1 1 1 5 > > 1 1 2 7 > > 1 1 3 6 > > 1 2 1 8 > > 1 2 2 3 > > 2 1 1 9 > > 2 1 2 6 > > 2 2 1 4 > > ; > > proc print; > > run; > > > ```

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