From: Max F on 10 May 2010 16:33 On May 10, 11:52 am, PJ <luxuem...(a)yahoo.com> wrote: > Please try below, > > data have; > > input @1 startdate date. @14 Finishdate date. id $ ; > format startdate finishdate date.; > cards ; > 04NOV07 04JAN08 55 > 08DEC07 07FEB08 55 > 02JAN08 03MAR08 55 > 07MAR08 07MAY08 55 > 10JUN05 10AUG05 76 > 17JUN05 16SEP05 76 > 09FEB06 11APR06 76 > 05NOV04 06DEC04 79 > 28MAR07 28MAY07 79 > ; > > run; > > data want; > merge have have(firstobs = 2 rename =startdate = next_start > keep=startdate); > run; > > data want(drop=next_start); > set want; > by id startdate notsorted; > if ^last.id and finishdate > next_start then finishdate = > next_start-1; > put (_all_) (=); > run; > > startdate=04NOV07 Finishdate=07DEC07 id=55 next_start=08DEC07 > startdate=08DEC07 Finishdate=01JAN08 id=55 next_start=02JAN08 > startdate=02JAN08 Finishdate=03MAR08 id=55 next_start=07MAR08 > startdate=07MAR08 Finishdate=07MAY08 id=55 next_start=10JUN05 > startdate=10JUN05 Finishdate=16JUN05 id=76 next_start=17JUN05 > startdate=17JUN05 Finishdate=16SEP05 id=76 next_start=09FEB06 > startdate=09FEB06 Finishdate=11APR06 id=76 next_start=05NOV04 > startdate=05NOV04 Finishdate=06DEC04 id=79 next_start=28MAR07 > startdate=28MAR07 Finishdate=28MAY07 id=79 next_start=. Thanks so much for your help. This is exactly what I want. I just wonder what is the function of that triangle sign before last.id?
From: data _null_; on 11 May 2010 11:32 On May 10, 1:07 pm, Max F <max...(a)yahoo.com> wrote: > On May 6, 4:40 am, "data _null_;" <datan...(a)gmail.com> wrote: > > > > > > > On May 5, 11:14 pm, Max F <max...(a)yahoo.com> wrote: > > > > I have a dataset with two dates. The startdate is in chronological > > > order by id: > > > > Startdate Finishdate id > > > > 04NOV07 04JAN08 55 > > > 08DEC07 07FEB08 55 > > > 02JAN08 03MAR08 55 > > > 07MAR08 07MAY08 55 > > > 10JUN05 10AUG05 76 > > > 17JUN05 16SEP05 76 > > > 09FEB06 11APR06 76 > > > 05NOV04 06DEC04 79 > > > 28MAR07 28MAY07 79 > > > > If the Finishdate is greater than the next Startdate, it needs to be > > > reset to one day before the Startdate. Therefore, the result would > > > look like this: > > > > Startdate Finishdate id > > > > 04NOV07 07DEC07 55 > > > 08DEC07 01JAN08 55 > > > 02JAN08 03MAR08 55 > > > 07MAR08 07MAY08 55 > > > 10JUN05 16JUN05 76 > > > 17JUN05 16SEP05 76 > > > 09FEB06 11APR06 76 > > > 05NOV04 06DEC04 79 > > > 28MAR07 28MAY07 79 > > > > Any help would be much appreciated. > > > A look ahead "merge" can be programmed with two sets. > > > data test; > > input (Startdate Finishdate)(:date.) id; > > format S: F: date9.; > > cards; > > 04NOV07 04JAN08 55 > > 08DEC07 07FEB08 55 > > 02JAN08 03MAR08 55 > > 07MAR08 07MAY08 55 > > 10JUN05 10AUG05 76 > > 17JUN05 16SEP05 76 > > 09FEB06 11APR06 76 > > 05NOV04 06DEC04 79 > > 28MAR07 28MAY07 79 > > ;;;; > > run; > > data test; > > set test end=eof; > > by id; > > if not eof then set test(firstobs=2 keep=F: > > rename=(FinishDate=NextFD)); > > if last.id then call missing(nextfd); > > run; > > proc print; > > run;- Hide quoted text - > > > - Show quoted text - > > The provided solution does not achieve what I intend to do. Anybody > who can help, please.- Hide quoted text - > > - Show quoted text - I did not intend to complete your program but rather show how to do the look ahead read in a single data step with a by variable. You should have been able to figure out that you needed next start date not next finish date. Then you should have been able to write a simple IF statement to check the condition is Finish Date Larger than Next Start Date.
From: ajs2004 on 11 May 2010 12:19 > what is the function of that triangle sign before last.id? ^ is a logical operator for 'not'. Ref: SAS Operators in Expressions Logical (Boolean) Operators and Expressions http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000780367.htm I don't know how you'd find that if you didn't already know, however. > > if ^last.id and finishdate > next_start then finishdate = > Thanks so much for your help. This is exactly what I want. I just > wonder what is the function of that triangle sign before last.id?
First
|
Prev
|
Pages: 1 2 Prev: SAS 64-bit windows 7 Next: Check if a macro variable ends with another string |