| Date: | Tue, 11 Dec 2007 15:22:43 -0600 |
| Reply-To: | Yu Zhang <zhangyu05@GMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Yu Zhang <zhangyu05@GMAIL.COM> |
| Subject: | Re: find consecutive dates |
|
| In-Reply-To: | <e2c3b73d-0b01-466e-a485-1476f0786305@d27g2000prf.googlegroups.com> |
| Content-Type: | text/plain; charset=ISO-8859-1 |
Well, I overlooked the problem and previous solution is not fully correct.
sorry for that.
the problem can be fixed, if we reassign the new date value to 'Begin' once
we detected the date is not consecutive. so add an ELSE statement like
following:
if strtdt=sum(begin,many) then
many+*1* ;
else begin=strtdt;
I tested it for 2 ,3,4, it seems working. But if there is anything goes
wrong, please let me know.
HTH
Yu
On Dec 11, 2007 2:46 PM, jingtailan@gmail.com <jingtailan@gmail.com> wrote:
> 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.
>
|