Date: Tue, 11 Dec 2007 12:46:27 -0800
Reply-To: "jingtailan@gmail.com" <jingtailan@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "jingtailan@gmail.com" <jingtailan@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: find consecutive dates
Content-Type: text/plain; charset=ISO-8859-1
On Dec 11, 2:43 pm, zhangy...@GMAIL.COM (Yu Zhang) wrote:
> see the red highlighted part, that is the only change was made.
>
> HTH
>
> Yu
>
> *data* desd;
>
> call missing(many,begin);
>
> do until (last.ptid or diff <= *0*);
>
> set find;
>
> by ptid dai strtdt ;
>
> if diff > *0* then do;
>
> if missing(begin) then begin = strtdt;
>
> if strtdt=sum(begin,many) then
>
> many+*1*;
>
> end;
>
> end;
>
> do until (last.ptid or diff<= *0*);
>
> set find;
>
> by ptid dai strtdt ;
>
> if (begin <= strtdt < begin+many ) and many >= *3* then output;
>
> end;
>
> format begin strtdt date9.;
> *
>
> run*;
>
> On Dec 11, 2007 10:46 AM, jingtai...@gmail.com <jingtai...@gmail.com> wrote:
>
>
>
> > all:
> > I posted a consecutive day find question and now I am looking for 3
> > consecutive STRTDT. I used the following codes, it is not working
> > properly, please advise, thanks a lot.
>
> > JINGTAILAN
>
> > -------------------------------------------------------------------------------------------------------------------------------------
>
> > data find;
> > input ptid dai diff strtdt mmddyy10.;
> > format strtdt date9.;
> > datalines;
>
> > 101 3 0.6 01012007
> > 101 3 0.2 01022007
> > 101 3 0.1 01032007
> > 101 3 0.1 01042007
> > 101 3 -0.1 01052007
> > 101 3 0.7 01062007
> > 101 5 -0.2 01072007
> > 101 5 0.1 01082007
> > 101 5 0.1 01092007
> > 101 5 0.4 01102007
> > 102 3 0 01022007
> > 102 3 0.3 01032007
> > 102 3 -0.6 01042007
> > 102 3 0.8 01152007
> > 102 3 0.2 01172007
> > 102 3 0.2 01182007
> > 103 3 0.6 01202007
> > 103 4 0.3 01012007
> > 103 4 0.6 01022007
> > 103 4 -0.5 01032007
> > 103 4 0.5 01042007
> > 103 4 0.15 01052007
>
> > ;
>
> > ----------------------------------------------------------------------------------------------------------------------------------
> > Desired output:
> > 101 3 0.6 01012007
> > 101 3 0.2 01022007
> > 101 3 0.1 01032007
> > 101 3 0.1 01042007
> > 101 5 0.1 01082007
> > 101 5 0.1 01092007
> > 101 5 0.4 01102007
>
> > ------------------------------------------------------------------------------------------------------------------------------------
> > My Codes:
>
> > proc sort data= find;
> > by ptid dai strtdt;
>
> > data desd;
>
> > do until (last.ptid or diff <= 0);
> > set find;
> > by ptid dai strtdt ;
> > if diff > 0 then do;
> > if missing(begin) then begin = strtdt;
> > many = many+1;
> > end;
> > end;
> > do until (last.ptid or diff<= 0);
> > set find;
> > by ptid dai strtdt ;
> > if (begin <= strtdt < begin+many ) and many >= 3 then output;
> > end;
> > format begin strtdt date9.;
> > run;- Hide quoted text -
>
> - Show quoted text -
Yu:
I played with the code. it works with many >= 3, if I change it to
Many >=2, then the output is NOT correctly displayed.
----------------------------------------------------------------------------------------------------------------
here is the output: (If change MANY> =2 )
101 3 0.6 01012007
101 3 0.2 01022007
101 3 0.1 01032007
101 3 0.1 01042007
101 5 0.1 01082007
101 5 0.1 01092007
101 5 0.4 01102007
103 4 0.5 01042007
103 4 0.15 01052007
-----------------------------------------------------------------------------------
The REAL output should be:
101 3 0.6 01012007
101 3 0.2 01022007
101 3 0.1 01032007
101 3 0.1 01042007
101 5 0.1 01082007
101 5 0.1 01092007
101 5 0.4 01102007
102 3 0 01022007
102 3 0.3 01032007
102 3 0.2 01172007
102 3 0.2 01182007
103 4 0.3 01012007
103 4 0.6 01022007
103 4 0.5 01042007
103 4 0.15 01052007
Any idea with what is going on?
tks again.