Date: Thu, 16 Jun 2005 15:03:31 -0400
Reply-To: gaoy2@email.uc.edu
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Gao Yun <gaoy2@EMAIL.UC.EDU>
Subject: Re: SAS help on averages...
Content-Type: text/plain; charset=us-ascii
Here is another code and output. It is only one data step.
I like easy and simple code.
*********************************************************
data help;
retain x1 x2 x3 x4 x5 j k;
if _n_ = 1 then do; j=1; k=5; end;
do i=j to k;
input x;
select (i);
when (1) x1=x;
when (2) x2=x;
when (3) x3=x;
when (4) x4=x;
when (5) x5=x;
end;
end;
j=mod(i-1,5)+1; k=j;
avg = mean(x1,x2,x3,x4,x5);
cards;
1
2
3
4
5
6
7
8
9
10
11
12
113
124
5
316
47
89
199
200
;
run;
proc print;
run;
Output:
Obs x1 x2 x3 x4 x5 .... avg
....
1 1 2 3 4 5 .... 3.0
2 6 2 3 4 5 .... 4.0
3 6 7 3 4 5 .... 5.0
4 6 7 8 4 5 .... 6.0
5 6 7 8 9 5 .... 7.0
6 6 7 8 9 10 .... 8.0
7 11 7 8 9 10 .... 9.0
8 11 12 8 9 10 .... 10.0
9 11 12 113 9 10 .... 31.0
10 11 12 113 124 10 .... 54.0
11 11 12 113 124 5 .... 53.0
12 316 12 113 124 5 .... 114.0
13 316 47 113 124 5 .... 121.0
14 316 47 89 124 5 .... 116.2
15 316 47 89 199 5 .... 131.2
16 316 47 89 199 200 .... 170.2
*******************************************************
Yun Gao
---- Original message ----
>Date: Thu, 16 Jun 2005 12:02:31 -0400
>From: Mike Smith <qt31416@GMAIL.COM>
>Subject: SAS help on averages...
>To: SAS-L@LISTSERV.UGA.EDU
>
>Hi guys,
>
>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.
>
>Thanks for your help.
>
>By the way, i changed my account here because, gmail
provides larger space
>for emails. Wish to hear from you all.
|