Date: Thu, 16 Jun 2005 10:25:43 -0700
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "David L. Cassell" <cassell.david@EPAMAIL.EPA.GOV>
Subject: Re: SAS help on averages...
Content-type: text/plain; charset=US-ASCII
Mike Smith <qt31416@GMAIL.COM> wrote back:
> Thanks for all who responded. I know my question wasn't that clear.
> data layout is simple:
> data help;
> input numbers;
> *and so on...;
> Say I have 5n observations, I want to build a data set with n
> such that the first observation is the average of the first five, in
> example, it's 5 :) , the second observation should be the average of
> second five, and so on, till the last observation which is the average
> the nth 5 observations
I see that you have already received a number of very good responses.
I just thought I would toss in one more.
PROC EXPAND (in the SAS/ETS package) is designed to handle this type
of problem (as well as expanding data in the other direction). If you
have SAS/ETS, you can use PROC EXPAND to do this in a straightforward
way. You can handle missing values, and you can even get the proc
to extrapolate at the end of the file if you don't have a multiple
of 5 for your record count. Also, you can handle multiple variables
at the same time (you can treat the variables differently too, if you
use more than one CONVERT statement)..
seed = 4958674;
do _n_ = 1 to 25;
number1 = int(25 * ranuni(seed));
number2 = int(15 * ranuni(seed));
proc print; run;
proc expand data=temp1 out=YourOut
factor=(1:5); /* we convert each 5 records into 1 output record */
convert number1 number2 / observed=average ;
proc print; run;
This *does* require the use of SAS/ETS. But it also gives you
a ton of flexibility.
David Cassell, CSC
Senior computing specialist