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 (April 2006, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sat, 29 Apr 2006 09:16:35 -0400
Reply-To:   "data _null_;" <datanull@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "data _null_;" <datanull@GMAIL.COM>
Subject:   Re: missing end dates
Comments:   To: David L Cassell <davidlcassell@msn.com>
In-Reply-To:   <BAY103-F1572EC02DC3A9DD802819AB0B30@phx.gbl>
Content-Type:   text/plain; charset=ISO-8859-1; format=flowed

Well you're pretty close. When 'terminated' end is not start minus 1. It is start.

On 4/29/06, David L Cassell <davidlcassell@msn.com> wrote: > markl@UAB.EDU wrote: > >I have data where segments only have sas start dates. I need to make end > >dates for each segment. > >End dates should be the day before the next segment start date, except > >where > >it is the last work segment before final termination. Then end date should > >be the final termination date. > >Any help appreciated. > >Data sample looks like this. > > > >id start end job segnum > >1 01011960 worker 1 > >1 02031970 terminated 2 > >2 03041978 workb 1 > >2 05041979 workc 2 > >2 06051079 terminated 3 > >4 11121980 worker 1 > >4 12301980 terminated 2 > >4 02031982 worker 3 > >4 11121983 terminated 4 > > First, a data sample is a lot nicer if you make it SAS code ready to > be read into someone's system. Like this: > > > data temp1; > informat start mmddyy8. job $10. ; > format start mmddyy10. ; > input id start job segnum; > datalines; > 1 01011960 worker 1 > 1 02031970 terminated 2 > 2 03041978 workb 1 > 2 05041979 workc 2 > 2 06051979 terminated 3 > 4 11121980 worker 1 > 4 12301980 terminated 2 > 4 02031982 worker 3 > 4 11121983 terminated 4 > ; > run; > > > Note that I turned the date strings into real SAS dates. That will > also make your life easier. Always remember that laziness (NOTE: > in the "Programming Perl" sense of the word) is one of the great > virtues of a programmer, and using SAS dates instead of icky strings > will make things easier later on. > > Then all you have to do is find a way to look ahead one step. There > are lots of ways to do that in SAS. I see that some people have > shown you several. Here's one more. I just read in the data set > twice and merge it with itself, but one of those versions has had its > first record cut off with FIRSTOBS=2, so it is telling us just what > the future will hold, one record at a time. Then the code becomes > a lot easier. > > > data temp2(drop=start2 id2 job2); > merge temp1(firstobs=2 drop=segnum rename=(start=start2 id=id2 job=job2)) > temp1; > if id=id2 & job^=:'term' then end=start2-1; > format end mmddyy10. ; > run; > > > Try this and print the results. Now when we move to the next ID, > or we find a terminated employee, we just don't create END. That's > all there is to it. Oh, and I formatted END just as I formatted START, > so it is easy to read the SAS date variables. That's more laziness on > my part. > > HTH, > David > -- > David L. Cassell > mathematical statistician > Design Pathways > 3115 NW Norwood Pl. > Corvallis OR 97330 > > _________________________________________________________________ > Don't just search. Find. Check out the new MSN Search! > http://search.msn.click-url.com/go/onm00200636ave/direct/01/ >


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