Insert missing dates(within id)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | *(Q) We trying to add in additional cases/records for clients where we have some missing records. * These are usually in the middle of a date range eg we have records for client no. 123 for 1/3/00, 2/3/00, 6/3/00 and 7/3/00 but not for 3,4 or 5th.... can you tell us how to create a record for the 3,4 and 5th? *(A) Solution posted to spss newsgroup by Raynald Levesque on 2002/03/11. DATA LIST LIST /id(F8.0) date1(SDATE). BEGIN DATA 122 2000/1/1 122 2000/1/2 123 2000/3/1 123 2000/3/2 123 2000/3/6 END DATA. LIST. VARIABLE WIDTH date1(11). SORT CASES BY id date1(A). DO IF $CASENUM>1 & id=LAG(id). COMPUTE days1=CTIME.DAYS(date1-LAG(date1)). END IF. CREATE days2=LEAD(days1,1). COMPUTE #oneday=60*60*24. DO IF MISSING(days2) OR days2=1. XSAVE OUTFILE='c:\\temp\\temp.sav'. ELSE. LOOP cnt=1 TO days2. + COMPUTE date1=LAG(date1)+#oneday*cnt. + XSAVE OUTFILE='c:\\temp\\temp1.sav'. END LOOP. END IF. EXECUTE. ADD FILES FILE='c:\\temp\\temp.sav' /FILE='c:\\temp\\temp1.sav' /DROP=days1 days2 cnt. SORT CASES BY id date1(A). |
Related pages
...