Date: Mon, 1 Dec 2008 16:35:30 -0500
Reply-To: Ya Huang <ya.huang@AMYLIN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ya Huang <ya.huang@AMYLIN.COM>
Subject: Re: Average last readings
Here is a SQL solution:
proc sql;
select distinct subid, mean(case when avc then score else . end) as
beforec, mean(case when avb then score else . end) as lowestb
from (select *, min(case when act='c' then obs else . end) as c1,
min(case when act='b' then obs else . end) as bc,
case when calculated c1 -4 <= obs < calculated c1 then 1 else . end
as avc,
case when calculated bc -1 <= obs <= calculated bc +1 then 1 else .
end as avb
from a group by subid)
group by subid
;
subid beforec lowestb
----------------------------
1 28.5 26.66667
2 30.5 27.33333
On Mon, 1 Dec 2008 16:15:52 -0500, Syk <sghb02@GMAIL.COM> wrote:
>Hi SAS-L
>
>I hope all of you had a wonderful thanks giving...
>
>I am still at it again... I want to compute
>
>1) Average score during the 3 hours (4 score readings) just before C.
>2) Average score of 3 readings centered on the lowest reading of B plus
>readings immediately before and after.
>
>Any help is greatly appreciated.
>
>
>data a;
>input obs subid score time time5. act $;
>datalines;
>1 1 25 8:30 a
>2 1 26 9:30 a
>3 1 27 10:30 a
>4 1 28 11:30 a
>5 1 30 12:30 a
>6 1 31 13:30 a
>7 1 33 14:30 a
>8 1 26 15:30 a
>9 1 27 16:30 a
>10 1 28 17:30 a
>11 1 27 18:30 b
>12 1 25 19:30 b --- lowest
>13 1 27 20:30 b
>14 1 28 21:30 b
>15 1 30 22:30 b
>16 1 31 23:30 b
>17 1 33 0:30 b -----
>18 1 26 1:30 b before c
>19 1 27 2:30 b
>20 1 28 3:30 b -----
>21 1 25 4:30 c
>22 1 26 5:30 c
>23 1 27 6:30 c
>24 1 25 7:30 c
>25 1 25 8:30 c
>26 2 25 13:00 a
>27 2 26 14:00 a
>28 2 27 15:00 a
>29 2 28 16:00 a
>30 2 30 17:00 a
>31 2 31 18:00 a
>32 2 33 19:00 a
>33 2 26 20:00 a
>34 2 27 21:00 a
>35 2 28 22:00 a
>36 2 28 23:00 b
>37 2 26 0:00 b
>38 2 24 1:00 b ------lowest
>39 2 28 2:00 b ----
>40 2 30 3:00 b before c
>41 2 31 4:00 b
>42 2 33 5:00 b ---
>43 2 26 6:00 c
>44 2 27 7:00 c
>45 2 28 8:00 c
>46 2 25 9:00 c
>47 2 26 10:00 c
>48 2 27 11:00 c
>49 2 28 12:00 c
>50 2 25 13:00 c
>;
>run;
>
>Wanted output
>id beforeC LowestB
>1 28.5 26.33
>2 24.4 26
>
>Thank you
|