LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 1999, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 21 Apr 1999 21:26:37 GMT
Reply-To:     FABIEN LABERENNE <flaberenne@CLARANET.FR>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         FABIEN LABERENNE <flaberenne@CLARANET.FR>
Subject:      Re: Using LAG Function to Decay a Variable over Time

Jim Savage a icrit dans le message <>... >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 >.65 power. > >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; > by market; >retain DECAYGRP; >DECAYGRP=GRP; >DECAYGRP=lag1(DECAYGRP)*.8); >DECAYGRP=SUM(of GRP DECAYGRP);); >if then DECAYGRP=GRP; /* want to start over for each market */ >run; > >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 > >Savage Genealogy: >Landers Genealogy: > > Hi ,

I don't know if i understood exactly your problem but try replacing thess lines >retain DECAYGRP; >DECAYGRP=GRP; >DECAYGRP=lag1(DECAYGRP)*.8); >DECAYGRP=SUM(of GRP DECAYGRP);); >if then DECAYGRP=GRP;

by these


According to me, you don't have to use the retain statement as its sounds to perform the same work as lag function I don't really know the function "SUM(of " that you use (I always perform proc means);

Good luck,



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