| Date: | Sat, 18 Apr 1998 16:56:30 GMT |
| Reply-To: | Renaud Langis <nakhob@MAT.ULAVAL.CA> |
| Sender: | "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU> |
| From: | Renaud Langis <nakhob@MAT.ULAVAL.CA> |
| Organization: | Universiti Laval |
| Subject: | Re: Cummulative product |
| Content-Type: | text/plain; charset=us-ascii |
On Sat, 18 Apr 1998 01:06:39 -0700, "Andrew James Llwellyn Cary"
<ajlcary@CaryConsulting.com> wrote:
>Try using a datastep. The one below does both the sum and the product.
>
>(untested code- assumes yourdata sorted by FIRM and YEAR)
>
>DATA CUMUL;
> SET yourdata;
> BY FIRM YEAR;
>
> RETAIN TOTSUM PRODUCT ;
>
> IF FIRST.YEAR THEN DO;
> TOTSUM=0;
> PRODUCT=1;
> END;
>
> IF AMOUNT NE . THEN DO;
> TOTSUM=TOTSUM+ AMOUNT;
> PRODUCT=PROUCT*AMOUNT;
> END;
>
> IF LAST.YEAR THEN OUTPUT;
>
>RUN;
I haven't tested the code so it may not work as is but it should be achievable.
PROC SQL;
CREATE TABLE cumul
SELECT SUM(amount) as totsum,PROD(amount) as product
FROM yourdata
ORDER BY firm year;
QUIT;
R
|