Date: Fri, 4 May 2007 13:50:52 -0400
Reply-To: "Richard A. DeVenezia" <rdevenezia@WILDBLUE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Richard A. DeVenezia" <rdevenezia@WILDBLUE.NET>
Organization: Internet News Service
Subject: Re: cumulative product?
"data _null_;" wrote:
> Actually with the proper initialization of VARCC is it more straight
> forward.
>
> data test2 ;
> varcc = 1;
> do until(last.varb);
> set test;
> by vara varb;
> varcc = varc * varcc;
> output;
> end;
> run;
This is a fine solution. If the desired output table is to have only the
resultant cumulative product of each by group, just drop the output and let
implicit output occur. It does not hurt to deliver the by group count
either.
data CuProd(keep=a b cpc n);
retain a b;
cpc = 1;
do n = 1 by 1 until (last.b);
set test;
by a b;
cpc = cpc * c;
end;
run;
if N is not wanted and column ordering is arbitrary, a simpler construct
would be
data CuProd2(keep=a b cpc);
do cpc = 1 by 0 until (last.b);
set test;
by a b;
cpc = cpc * c ;
end;
run;
--
Richard A. DeVenezia
http://www.devenezia.com/