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 (July 2010, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 7 Jul 2010 22:46:54 -0400
Reply-To:   Arthur Tabachneck <art297@NETSCAPE.NET>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Arthur Tabachneck <art297@NETSCAPE.NET>
Subject:   Re: Logic - Data restructure

p.s., The logic behind the method is described at: http://www.sascommunity.org/wiki/Look-Ahead_and_Look-Back

Art ---------- On Wed, 7 Jul 2010 13:41:08 -0700, Arthur Tabachneck <art297@NETSCAPE.NET> wrote:

>Al, > >I think that the look ahead look back code proposed by Howard Schreier >a few years ago will do exactly what you want. E.g., > >data have; > format dt date9.; > informat dt date9.; > input pat vis dt date9.; > cards; >1 1 11FEB2010 >1 2 13FEB2010 >1 3 14FEB2010 >2 1 11MAR2010 >2 2 06MAR2010 >2 3 20MAR2010 >3 1 05MAY2010 >3 2 08MAY2010 >3 3 12MAY2010 >3 4 10MAY2010 >; > >data want (drop=next: prev:); > set have; > by pat; > call missing(flag); > set have ( firstobs = 2 keep = dt > rename = (dt = next_dt) ) > have ( obs = 1 drop = _all_ ); > format prev_dt next_dt date9.; > prev_dt=lag(dt); > if last.pat then next_dt=.; > if (not(missing(next_dt)) and dt gt next_dt) or > dt lt prev_dt > then flag=1; >run; > >HTH, >Art >------------ >On Jul 7, 2:38 pm, Al <ali6...@gmail.com> wrote: >> Dear all: >> >> This is the dataset i have .. >> >> pat vis dt >> 1 1 11FEB2010 >> 1 2 13FEB2010 >> 1 3 14FEB2010 >> 2 1 11MAR2010 >> 2 2 06MAR2010 >> 2 3 20MAR2010 >> 3 1 05MAY2010 >> 3 2 08MAY2010 >> 3 3 12MAY2010 >> 3 4 10MAY2010 >> >> I am trying to get to this dataset with a flag variable >> to see if any of the dt values are placed out of the order per pat >> >> pat vis dt flag >> 1 1 11FEB2010 >> 1 2 13FEB2010 >> 1 3 14FEB2010 >> 2 1 11MAR2010 1 >> 2 2 06MAR2010 1 >> 2 3 20MAR2010 >> 3 1 05MAY2010 >> 3 2 08MAY2010 >> 3 3 12MAY2010 1 >> 3 4 10MAY2010 1 >> >> Any suggestions >> >> Thanks in advance >> Al


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