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 (June 2005, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 16 Jun 2005 10:25:43 -0700
Reply-To:     cassell.david@EPAMAIL.EPA.GOV
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "David L. Cassell" <cassell.david@EPAMAIL.EPA.GOV>
Subject:      Re: SAS help on averages...
In-Reply-To:  <>
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. Well my > data layout is simple: > > data help; > input numbers; > cards; > 3 > 4 > 1 > 17 > 0 > 12 > *and so on...; > ; > run; > > Say I have 5n observations, I want to build a data set with n observations > such that the first observation is the average of the first five, in my > example, it's 5 :) , the second observation should be the average of the > second five, and so on, till the last observation which is the average of > 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)..

data temp1(drop=seed); seed = 4958674; do _n_ = 1 to 25; number1 = int(25 * ranuni(seed)); number2 = int(15 * ranuni(seed)); output; end; run;

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 ; run;

proc print; run;

This *does* require the use of SAS/ETS. But it also gives you a ton of flexibility.

HTH, David -- David Cassell, CSC Senior computing specialist mathematical statistician

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