|
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> AnoniDeer
> Sent: Friday, April 11, 2008 4:44 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: how to deal with multiple ID
>
> I have a dataset like this.How could I get the difference between the
> third and fourth observations for each of the group? for example for
> the group 1 I need to get the difference for the observation of 45 and
> 34. For the second group I need the difference of 76-34 and so on...
> How to write a program to realize this? Thanks so much!
>
I am assuming that your sample data faithfully represents what your data actually looks like: in sorted order, each group having exactly 4 observations. Something like this will work
data have;
input group x;
cards;
1 23
1 .
1 34
1 45
2 45
2 89
2 34
2 76
4 23
4 12
4 23
4 12
;
run;
data want ;
set have;
by group;
diff_34 = dif(x);
if last.group then output;
run;
If this doesn't meet your needs, write back to the list with more detail.
Hope this is helpful,
Dan
Daniel Nordlund
Bothell, WA USA
|