LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (April 1998, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 3 Apr 1998 23:31:55 GMT
Reply-To:   dr_zeus@APE_PLANET.COM
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   dr_zeus@APE_PLANET.COM
Organization:   Verio Northern California
Subject:   Re: subtraction across obs

Lynn Nicole Lethbridge <lynnl@is.dal.ca> wrote: : Does anyone know of an efficient way to do subtraction across observations : in SAS. For example suppose I have the following data: : ID var1 var2 : 1 4 7 : 1 3 8 : 2 6 10 : 2 5 7 : I'd like to subtract var1 from var1 in the previous observation and var2 : from var2 in the previous observation BUT ONLY WHERE THERE ARE 2 IDS. So : for ID=4 or ID=7 there will be no subtraction.

use a sort followed with a data step which uses set and by statements. then use the first./last. syntax to identify where new idss begin. then, rather than using the lag function and then subtracting, (as others have suggested), use the DIFn(var) function to compute the n'th laggin difference.

steve


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