Date: Wed, 27 Jan 2010 10:18:20 -0800
Reply-To: Sri <subhadrasri@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Sri <subhadrasri@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: Deleting next observation in SAS
Content-Type: text/plain; charset=ISO-8859-1
On Jan 27, 12:04 pm, zhangy...@GMAIL.COM (Yu Zhang) wrote:
> Is this what you need?
>
> 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
> ;
> run;
>
> data have;
>
> do n=1 by 1 until(last.tmp_up);
> set test;
> by pt tmp_up notsorted;
> end;
>
> do _n_=1 to n;
> set test;
> if not(tmp_up=0 and n>1) then output;
> end;
> drop n;
> run;
>
>
>
> On Wed, Jan 27, 2010 at 10:13 AM, Sri <subhadra...@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.- Hide quoted text -
>
> - Show quoted text -
BIG THANKS to all ..... i never heard of "NOTSORTED" before ....
thanks again for the quick response, i really appreciate it.
|