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 (August 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 7 Aug 2006 23:04:16 -0400
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject:      Re: first none missing date

On Mon, 7 Aug 2006 09:40:10 -0700, Richard Gong <gongcon@GMAIL.COM> wrote:

>* Hi, > >I have the following data set (test) and try to create two new variables >start_date and end_date. The start_date is the first none missing date and >the end date is the last none-missing date. > >data* test; >input patno date date9.; >format date date9.; >datalines; >1 . >1 09JUL1994 >1 05JUL1994 >1 . >1 27JUL1994 >run; > >*The final result will be the following:* >patno date start_date end_date >1 . 05JUL1994 27JUL1994 1 09JUL1994 05JUL1994 >27JUL1994 >1 05JUL1994 05JUL1994 27JUL1994 >1 . 05JUL1994 27JUL1994 >1 27JUL1994 05JUL1994 27JUL1994 > > >I tried to *sort* the data set first *by* patno and date and use retain and >*first.*patno to assign the value, but the problem is that I don't know how >to deal with the missing value.

Try this

data start_end; keep patno start_date end_date; set test; by patno; retain start_date end_date; if first. patno then do; start_date = .; end_date = .; end; if missing(start_date) then start_date = date; if not missing (date) then end_date = date; if last.patno then output; format start_date end_date date9.; run;

> >Best Regards > >gongcon


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