```Date: Wed, 30 Mar 2005 09:31:36 -0600 Reply-To: PuddingDotManAtGmailDotCom@listserv.cc.uga.edu Sender: "SAS(r) Discussion" From: Pudding Man Subject: Re: First/Last question - averaging last 4 observations Comments: To: anne olean In-Reply-To: <20050329225315.6723.qmail@web51501.mail.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1 Here's an approach (tested W2k 9.1.3) that some might find mildly interesting: data dataUV(drop = _:); do id=1 to 2; do _j=1 to 20*ranuni(9); x=ceil(9 * ranuni(4)); if ranuni(1) > .3 then x=.; output; end; end; run; data test(drop = _: x); array _xx(4); do until (last.id); set dataUV; by id; if missing(x) then continue; N = sum(N, 1); call poke(peekc(addr(_xx(1)), 3 * 8), addr(_xx(2)), 3 * 8); call poke(peekc(addr(x), 8), addr(_xx(1)), 8); end; if N >= 4 then x_avg=mean(of _xx:); else put / '*** < 4 data points for ID ' id N= '***' / _all_ /; run; It just constructs a queue with a 4 element array and uses 2 CALL POKE's to drive the data thru it. Prosit, Puddin' ***************************************************************** *** Puddin' Man PuddingDotMan at GmailDotCom ** *****************************************************************; "Mit der Dummheit kaempfen Goetter selbst vergebens!" -Friedrich Schiller (1759-1805) On Tue, 29 Mar 2005 14:53:15 -0800, anne olean wrote: > Hi all, > > I have a dataset with ~ 10 repeated observations per > subject. I want compute an average of the last 4 > observations of each subject. Because some subjects > are missing data, the average will not always be > observations 7-10. I thought of using first/last but > all I got it to do is capture the last observation. Is > there some other function that I have to use? any > feedback is much appreciated. thanks, ako > > data test; set dataUV; > by id; > > if last.id then do; ave=score; output;end; > keep id tx score ave; > run; > > > __________________________________ > Do you Yahoo!? > Yahoo! Small Business - Try our new resources site! > http://smallbusiness.yahoo.com/resources/ > ```

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