    * Cross-sectional Analysis Stats Paper Kaplan-Meier.sps.
    * Restricted to teeth retreated with fillings, crowns/inlays or extractions.

    * Written by PSKL on 19/8/02.
    * This analysis does not distinguish between different treatment types.

    * Create File of all tooth treated records after 31/3/2000 with date of acceptance before May 2001.

    	get file='D:\Longitudinal Data\dob1965acc199904to200104 teeth.sav'.
    	* estimate date of placing of treatment.
    	compute doplac=doacc.
    	if (not(missing(docomp)))doplac=docomp.

    	* Restrict analysis to date of completion/acceptance after 31/3/2000 and date of acceptance before May 2001.

    	select if (doplac>yrmoda(2000,03,31)*60*60*24
    		and doacc<yrmoda(2001,05,01)*60*60*24).

    	formats doplac (edate10).

    	save outfile='c:\temp1.sav'.

    * Reduce to records of teeth treated with fillings, crowns/inlays or extractions from April 2000 to April 2001.

    	get file='c:\temp1.sav'.
    	select if (any(trtcode,1401,1402,1403,1404,1421,1426)
                                  or range(trtcode,1701,1799) or range(trtcode,2101,2299)).
    	* Reduce to one record per tooth per course of treatment, by using lowest trtcode.
    	sort cases by surname initial sex dobirth doacc quadrant tooth trtcode.
    	aggregate outfile=* /presorted
     	/break surname initial sex dobirth doacc quadrant tooth
     	/ doplac docomp dorec schednum fpcnum persnum partnum suffix postcode exempcod  trtcode
     	=first(doplac docomp dorec schednum fpcnum persnum partnum suffix postcode exempcod trtcode).
    	compute retreat=1.
    	if (any(trtcode,1401,1402,1403,1404,1421,1426))retreat=0.
          * sort in descending order of date of acceptance.
    	sort cases by surname initial sex dobirth quadrant tooth (a) doacc(d) .
    	save outfile='c:\temp2.sav'.

    * Add date of retreatment, if any, to filling records, then get rid of non-filling records.
    * Flag all filling courses followed by crown, extraction or bridge.

    	get file='c:\temp2.sav'.
    	if(retreat=0 and
    	 surname = lag(surname) and
     	 initial = lag(initial) and
     	 sex = lag(sex) and
     	 dobirth = lag(dobirth) and
     	 quadrant = lag(quadrant) and
     	 tooth = lag(tooth)) doretr=lag(doacc).
    	if (not(missing(doretr)) and lag(retreat)=1)doloss=doretr.
    	formats doplac doretr doloss (EDATE10).
    	execute.
    	select if (retreat=0).
    	* sort to save processing time later.
    	sort cases by surname initial sex dobirth quadrant tooth doplac trtcode.
    	save outfile='c:\temp3.sav'.

    * At this stage we have a record for each tooth treatment record.
    * If the tooth was retreated then doretr is not missing.
    * Create time and reintervention variables and assume censoring on 30/4/2001, or after 365 days
    * whichever is earlier.Ignore cases with doplac>30/4/2001.

    get file='c:\temp3.sav'.
    select if (doplac<date.dmy(31,4,2001)).
    compute reint=0.
    compute time=ctime.days(doretr-doplac).
    if (range(time,1,365))reint=1.
    if (reint=0) time=min(ctime.days(date.dmy(31,4,2001)-doplac),365).

    * Kaplan-Meier Survivor Functions.

    KM
      time  /STATUS=reint(1)
      /PRINT NONE
      /plot=survival
      /save Survival(survtrt) se.

# Kaplan-Meier

Notes
Output Created | 29-AUG-2002 15:49:00
Comments |
Input | Data | c:\temp3.sav
File Label | Aggregated File
Filter | <none>
Weight | <none>
Split File | <none>
N of Rows in Working Data File | 364124
Syntax | KM time /STATUS=reint(1) /PRINT NONE /plot=survival /save Survival(survtrt) se.
Resources | Elapsed Time | 0:03:15.00