```Date: Sat, 24 Jul 2004 01:15:50 GMT Reply-To: Arthur Tabachneck Sender: "SAS(r) Discussion" From: Arthur Tabachneck Subject: Re: Last. minus First. Thomas, You could try something like the following: Art data one; input id \$ x x1 x2; cards; a 10 0.5 0.9 a 11 0.55 0.8 a 12 0.5 0.6 a 13 0.45 0.55 b 1 0.1 0.15 b 2 0.2 0.25 b 3 0.15 0.2 ; run; data two (keep=id firstx lastx); retain firstx lastx; set one; by id; if first.id then firstx=x; else if last.id then do; lastx=x; output; end; run; data three (drop=firstx lastx); merge one two; by id; diff=lastx-firstx; run; ------ "Thomas" wrote in message news:200407240034.i6O0YQQ21115@listserv.cc.uga.edu... > Hi all, > > I have a dataset as belows, how do I compute the (Last.x - First.x), last > value of x minus first value of x, for each id? The input and desired > output are attached as belows. > > Thanks a lot! > Thomas > > *input; > id x x1 x2 > a 10 0.5 0.9 > a 11 0.55 0.8 > a 12 0.5 0.6 > a 13 0.45 0.55 > b 1 0.1 0.15 > b 2 0.2 0.25 > b 3 0.15 0.2 > > *expected output; > id x x1 x2 diff > a 10 0.5 0.9 3 > a 11 0.55 0.8 3 > a 12 0.5 0.6 3 > a 13 0.45 0.55 3 > b 1 0.1 0.15 2 > b 2 0.2 0.25 2 > b 3 0.15 0.2 2 ```

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