```Date: Wed, 24 Jul 2002 09:03:54 -0700 Reply-To: Stig Eide Sender: "SAS(r) Discussion" From: Stig Eide Organization: http://groups.google.com/ Subject: Re: how to get the mean of three month for each category Content-Type: text/plain; charset=ISO-8859-1 If date is a SAS date value, you could sort the table by category and date. Then you can use the lag function. Here is some untested code: *If the date variable is character, you should convert it to SAS date value first; proc sort data=dt; by category date; run; data dt(drop=count); set dt; by category; retain count 0; if first.category then count=0; else count+1; if count > 2 then AVERAGE=mean(lag1(return),lag2(return),lag3(return)); run; Good luck! Stig Eide gdx@CATS.UCSC.EDU (dongxu) wrote in message news:<5.1.0.14.0.20020724012924.00b9cd58@cats.ucsc.edu>... > I have the following data set.How can i get the average of latest three > month. for example: in apr78, i want to get the average return of > jan78, feb78, mar78 for each category. in may78, i want to get the average > return of feb78, mar78,apr78 for each category. And so on. > Thank you for your reply. > > Obs date category return > > 1 JAN78 WLG -0.06970 > 2 JAN78 WLV -0.06270 > > 46 AUG78 WMV 0.06320 > 47 AUG78 WSG 0.08700 > 48 AUG78 WSV 0.06230 ```

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