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 (December 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 10 Dec 2004 21:57:43 -0500
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject:      Re: Detect gaps and populate a variable

Here's my IF-less solution:

data want; set have; by cnty_rte; retain gap; gap = sum(gap, begmp>lag(endmp) ) * (not first.cnty_rte); run;

On Mon, 6 Dec 2004 15:27:41 -0500, Mohamedshah, Yusuf <Yusuf.Mohamedshah@FHWA.DOT.GOV> wrote:

>Dear all > >I have following dataset of State route-milepost system. What I want is to write a code that can detect gaps for a given route and based on how many gaps are for a given route, populate a variable indicating the number of the gap. > >cnty_rte begmp endmp > >0745609 0.01 0.6 >0745609 0.6 1.2 >0745609 1.6 2.5 >0745609 2.5 3.0 >0745609 3.0 4.5 >0745609 4.9 6.2 >0745609 6.2 9.8 >0745609 9.8 10.5 >0745609 10.5 11.5 >0745609 11.5 12.6 >0745610 0.0 3.6 >0745610 3.6 7.8 >0745610 9.2 10.1 >0745610 10.1 12.3 >.... >.... > > >What I want is the following output with a 'gap' variable coded as: > >cnty_rte begmp endmp gap > >0745609 0.01 0.6 0 >0745609 0.6 1.2 0 >0745609 1.6 2.5 1 >0745609 2.5 3.0 1 >0745609 3.0 4.5 1 >0745609 4.9 6.2 2 >0745609 6.2 9.8 2 >0745609 9.8 10.5 2 >0745609 10.5 11.5 2 >0745609 11.5 12.6 2 >0745610 0.0 3.6 0 >0745610 3.6 7.8 0 >0745610 9.2 10.1 1 >0745610 10.1 12.3 1 >.... >.... > >So the 'gap' goes from 0 to 2 since there are two gaps in the first route. And then it becomes zero because a route starts and goes from 0 to 1 since there is only one gap. > >Any help would be appreciated. > >Thanks


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