LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 2009, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 20 Apr 2009 11:09:10 -0400
Reply-To:   Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject:   Re: needed help regarding substraction
Comments:   To: hadsomeraja@GMAIL.COM

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 */


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