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 (January 2010, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 27 Jan 2010 10:53:10 -0600
Reply-To:     "Data _null_;" <iebupdte@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Data _null_;" <iebupdte@GMAIL.COM>
Subject:      Re: Deleting next observation in SAS
Comments: To: Sri <subhadrasri@gmail.com>
In-Reply-To:  <dd45c67e-9898-48fb-bd93-d68684425721@w12g2000vbj.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1

This can be address easily with FIRST and LAST but you will also need NOTSORTED.

data want; set test; by NOTSORTED pt tmp_up; _obs_ + 1; * to see which obs are kept/deleted; if tmp_up eq 0 and not(first.tmp_up and last.tmp_up) then delete; run;

pt dtc tmp_up _obs_

1001 01JAN2009 1 1 20MAR2009 1 5

1002 05JAN2009 1 6 03FEB2009 0 7 18MAR2009 1 8 20APR2009 0 9 22APR2009 1 10

1003 13JAN2009 0 11 19FEB2009 1 12 21FEB2009 1 13 15APR2009 1 16 23MAY2009 1 17

On 1/27/10, Sri <subhadrasri@gmail.com> wrote: > Hello All, > I'm trying to delete an observation based upon the next occurrence of > the data. I tried to use lag function and retain statement (may be I > did not use them in a right way) but none of them gave me the results > I wanted. > > Here is the sample data creation program: > > data test; > input pt $4. dtc date9. tmp_up ; > format dtc date9.; > cards; > 100101JAN20091 > 100109JAN20090 > 100111JAN20090 > 100118FEB20090 > 100120MAR20091 > 100205JAN20091 > 100203FEB20090 > 100218MAR20091 > 100220APR20090 > 100222APR20091 > 100313JAN20090 > 100319FEB20091 > 100321FEB20091 > 100323FEB20090 > 100313MAR20090 > 100315APR20091 > 100323MAY20091 > ; > > Data looks like this: > > obs pt dtc tmp_up > 1 1001 1-Jan-09 1 > 2 1001 9-Jan-09 0 > 3 1001 11-Jan-09 0 > 4 1001 18-Feb-09 0 > 5 1001 20-Mar-09 1 > 6 1002 5-Jan-09 1 > 7 1002 3-Feb-09 0 > 8 1002 18-Mar-09 1 > 9 1002 20-Apr-09 0 > 10 1002 22-Apr-09 1 > 11 1003 13-Jan-09 0 > 12 1003 19-Feb-09 1 > 13 1003 21-Feb-09 1 > 14 1003 23-Feb-09 0 > 15 1003 13-Mar-09 0 > 16 1003 15-Apr-09 1 > 17 1003 23-May-09 1 > > My logic should check if the variable tmp_up has 0 or 1 for each pt. > If it has 0, then it should check the value of tmp_up in the next > record. If it finds consecutive zeros, then it should delete all those > records until it comes across value 1 in the variable tmp_up for the > same pt. In the above data, it should delete obs=2,3,4 for pt=1001 and > obs=14,15 for pt=1003. > > Any help in this matter is highly appreciated. > > Thanks in advance. >


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