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 (March 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 19 Mar 2004 13:40:18 -0800
Reply-To:     shiling zhang <shiling99@YAHOO.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         shiling zhang <shiling99@YAHOO.COM>
Organization: http://groups.google.com
Subject:      Re: Help with an array
Content-Type: text/plain; charset=ISO-8859-1

HTH.

data test ; informat dateA dateB date9. ; input idA idB dateA dateB ; datalines; 1 1 01JAN1981 10JAN1981 1 2 02JAN1981 15JAN1981 1 3 01AUG1990 30AUG1990 1 3 02AUG1990 31AUG1990 1 4 24SEP1995 24SEP1995 2 5 17OCT2000 19OCT2000 2 6 29JUN1981 29JUN1981 ;

proc sort data= test out=sortedTest ; by idA dateA dateB ; run;

data temp; set sortedTest; by idA; array _date(2) _temporary_; if first.idA then do; _date(1)=.; _date(2)=.; end; if not first.idA then do; if _date(1) <= dateA <= _date(2) then flag='Overlap'; else flag='Non'; end; output; _date(1)=dateA; _date(2)=dateB; run;

proc print; run;

cynqiu@YAHOO.COM (Cynthia Qiu) wrote in message news:<200403190434.i2J4YwV31135@listserv.cc.uga.edu>... > Hi, > > I'm trying to use arrays to indentify records with the same ID (idA) that > have "overlapping" dates. For example, in the second record of the "test" > data below, the value of dateA (02JAN1981) is after the value of dateA in > the first record. For instances like this I would like to set the flag > variable in my program to 1. However it is not working. Can someone help? > > > /***************************************************/ > > data test ; > input idA idB dateA date11. dateB date11. ; > datalines; > 1 1 01JAN1981 10JAN1981 > 1 2 02JAN1981 15JAN1981 > 1 3 01AUG1990 30AUG1990 > 1 4 24SEP1995 24SEP1995 > 2 5 17OCT2000 19OCT2000 > 2 6 29JUN1981 29JUN1981 > ; > > proc sort > data= test > out=sortedTest ; > by idA dateA dateB ; > run; > > data a; > if EOF then call symput ('num',LEFT(PUT(maxcnt,8.))); > set test end=EOF; > by idA; > retain maxcnt 0; > if first.idA then count=0; > count+1; > if last.idA and count>maxcnt then maxcnt=count; > run; > %put Max number of events per idA = &num ; > > proc sort > data = test ; > by idA dateA dateB idB ; > run ; > > data flat (keep=idA dateA1-dateA&num dateB1-dateB&num > idB1-idB&num count); > set test ; > by idA dateA dateB idB ; > retain dateA1-dateA&num dateB1-dateB&num > idB1-idB&num ; > array beg ( &num ) dateA1 - dateA&num ; > array end ( &num ) dateB1 - dateB&num ; > array ids ( &num ) idB1 - idB&num ; > > if first.idA then do; > do i = 1 to dim(beg) ; > beg(i)=-1; > end(i)=-1; > ids(i)=-1; > end; > count=0; > end; > count+1; > beg(count)=dateA; > end(count)=dateB; > ids(count)=idB; > if last.idA then output; > run; > > data overlap ; > set flat; > array beg (&num ) dateA1 - dateA&num ; > array end (&num ) dateB1 - dateB&num ; > array ids (&num ) idB1 - idB&num ; > > if count > 1 then do ; > do j = 1 to &num-2 ; > k = j+1; > > if ( beg(j) le beg(K) le end(j) ) and > ( ids(j) ne ids(k) ne ids(k+1) ) > then flag = 1; > end; > end; > run ; > > data restore ; > merge test > overlap ; > by idA; > run ;


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