Date: Wed, 21 Apr 1999 19:58:47 GMT
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Jim Savage <ljas@EARTHLINK.NET>
Organization: EarthLink Network, Inc.
Subject: Using LAG Function to Decay a Variable over Time
Content-Type: text/plain; charset=us-ascii
I am trying to do a simple calculation in which I want to have the values of a
new variable build up based on the values of an input variable and then decay
when the input variable declines. This is being used in Advertising research
where we calculate a decayed/smoothed measure based on TV Gross Rating Points
which are usually spikes or pulses. Here's the logic that I am trying to do:
Decayed GRP's for week 1 = Input GRP's for week1
Week 2 decayed GRP's = Input GRP's for week 2 + 80% of the Wk1 decayed GRP's
Week 3 decayed GRP's = Input GRP's for week 3 + 80% of the Wk2 decayed GRP's
After these decay operations are done for each week the result is raised to the
This works really well in a spreadsheet, but I thought it would be easier in
SAS, since that's where I'm going to do the model anyway.
Here's what I tried with no success. I think there is something I don't
understand about the LAG function.
Data two; set one;
DECAYGRP=SUM(of GRP DECAYGRP););
if first.market then DECAYGRP=GRP; /* want to start over for each market */
The first 2 observations are calculated correctly, but from then
on the values are wrong. Anyone have any thoughts as to
what I can do to fix this problem?
Jim Savage at firstname.lastname@example.org
Savage Genealogy: http://home.earthlink.net/~ljas/savage/index.htm
Landers Genealogy: http://home.earthlink.net/~ljas/index.htm