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 (December 2007, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 12 Dec 2007 08:41:57 -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:      find consecutive dates-debug
Comments: To: sas-l@uga.edu
Content-Type: text/plain; charset=ISO-8859-1

All:

I am trying to find out consecutive dates and got lots of help from SAS-L. I have a data set look like this and would like to find the patient whose diff>0 in consecutive 7 dates and output the >= 7 dates.

I got some thing wrong in my code, please advise . thanks a lot.

-------------------------------------------------------------------------------------------------------------------------------

data find1; input ptid dai strtdt diff ; datalines;

001 3 3 0 001 3 4 -0.5 001 3 5 0 001 3 6 0 001 3 7 -0.5 001 3 9 0 001 3 10 0 001 3 11 0 001 3 12 0 001 3 13 0 001 3 14 -0.5 001 3 15 -0.5 001 3 16 -0.5 001 3 17 0 001 3 18 0 001 3 19 0 001 3 20 0 001 3 21 0 001 3 22 0 001 3 23 0 001 3 27 0 001 3 28 0 001 3 29 0 001 5 3 -0.3 001 5 4 0 001 5 5 0 001 5 6 0 001 5 7 0 001 5 8 0 001 5 9 0 001 5 10 0 001 5 11 0 001 5 14 -0.5 001 5 15 -0.5 001 5 16 -0.5 001 5 17 0 001 5 18 0 001 5 19 0 001 5 20 0 001 5 22 0 001 5 27 0 001 5 29 0 ;

proc sort data= find1; by ptid dai strtdt;

data desd2; call missing(many,begin); ;

do until (last.ptid or diff <0); set find1; by ptid dai strtdt ;

if diff >=0 then do; if missing(begin) then begin = strtdt; if strtdt=sum(begin,many) then many+1; else begin=strtdt; end; end;

do until (last.ptid or diff<0); set find1; by ptid dai strtdt ; if (begin <= strtdt < begin+many ) and many >= 7 then output; end;

run;

/* the output */ 001 3 29 0 001 5 17 0 001 5 18 0 001 5 19 0 001 5 20 0 001 5 22 0 001 5 27 0 001 5 29 0

/*Desired output */

001 3 17 0 001 3 18 0 001 3 19 0 001 3 20 0 001 3 21 0 001 3 22 0 001 3 23 0 001 3 27 0 001 3 28 0 001 3 29 0 001 5 17 0 001 5 18 0 001 5 19 0 001 5 20 0 001 5 22 0 001 5 27 0 001 5 29 0 ;


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