Date: Fri, 4 May 2007 11:18:34 -0400
Reply-To: Wensui Liu <liuwensui@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Wensui Liu <liuwensui@GMAIL.COM>
Subject: Re: cumulative product?
In-Reply-To: <1178191211.064832.152770@e65g2000hsc.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
celiaca,
here is the hash solution for your reading pleasure.
data _null_;
if 0 then set test;
dcl hash h (hashexp: 16);
h.definekey ('VarA', 'VarB');
h.definedata('VarA', 'VarB', 'product');
h.definedone();
do until (eof);
set test end = eof;
if h.find() ~= 0 then do;
product = VarC;
end;
product = product * VarC;
h.replace();
end;
rc = h.output(dataset: 'product');
run;
On 5/3/07, celiacai@gmail.com <celiacai@gmail.com> wrote:
> Hi
>
> I knew there's certain way to calculate subgroup cumulative sum in a
> table...but how can I calculate the cumulative product of subgroups
> within a dataset?
>
> Say, the ovservations are sorted by variable A,B and C (namely
> subgrouped twice), and I want to find out the product of all Cs within
> each B-group. How could I do that?
>
> celia
>
--
WenSui Liu
A lousy statistician who happens to know a little programming
(http://spaces.msn.com/statcompute/blog)