|
On Mon, 20 Apr 2009 07:26:00 -0700, Raju <hadsomeraja@GMAIL.COM> wrote:
>Hi All,
>
>I have dataset like
>
>id day
>1 1
>1 2
>1 3
>1 4
>2 1
>2 3
>2 7
>
>I need a difference between day, means I wann subtract from next obs
>like
>
>id day day_n
>1 1 1
>1 2 1
>1 3 1
>1 4 0
>2 1 2
>2 3 4
>2 7 0
>
>Please give me some clue
hi, Raju,
here are some clues (and some more). hth.
cheers,
chang
/* test data */
data one;
input id day @@;
cards;
1 1 1 2 1 3 1 4
2 1 2 3 2 7
;
run;
/* attach the difference, day[obs+1] - day[obs],
to the observation, within the id group.
for the last.id, put zero. */
proc sort data=one;
by id day;
run;
data two;
set one end=end;
by id;
if not end then
set one(firstobs=2 keep=day rename=(day=next_day));
day_n = ifn(last.id, 0, next_day - day);
drop next_day;
run;
/* check */
proc print data=two noobs;
run;
/* on lst
id day day_n
1 1 1
1 2 1
1 3 1
1 4 0
2 1 2
2 3 4
2 7 0
*/
|