********************************************************************************************** This code was created 090914 by Anna Törner, anna.torner@smi.se, Swedish Institute for Infectious Disease Control. The purpose of the code is to illustrate how calculations for a cumulative SIR graph may be set up. In addition to the code below, a macro for time splitting is needed. The macro used below is the lexis macro written by Bendix Carstensen and this macro may be downloaded from: (http://staff.pubhealth.ku.dk/~bxc/Lexis/). The code given below includes the use of this lexis macro, but the actual macro itself must be downloaded form the referenced page. The macro takes one parameter, i, size of the time window. This value is currently set to 10, for trial runs, but should be adjusted to an appropriate value, e.g. 730 (2 years). Two data sets, COHORT and INC, are needed as input data sets for the code and macros below: COHORT is the data set holding information on the cohort. The dataset COHORT should contain the following variables: SEX Man/Woman (coded as "1" and "2") BIRTHDATE Date of birth (date format) ENTRY Date of entry into cohort, i.e. when person is identified as member of cohort (date format) EXIT Date of studied outcome, death, emigration or end of follow-up, whichever occurs first (date format) EXITSTATUS Is set to "1" if the individual experiences the outcome of interest, otherwise "0". DIADATE The date of diagnosis of the outcome studied. If patient does not experience this outcome this is set to "." (missing) (date format). INC is the data set holding incidence rate of the studied outcome in the reference population. The INC data set should contain the following variables: SEX Man/Woman (coded as "1" and "2") YEAR Calender year for which the incidence rate is valid AGE Age group for which the incidence rate is given INC Incidence rate per 100 000 individuals *********************************************************************************************; *STEP 1 - SETTING UP PROCEDURE FOR CALCULATING SIR *********************************************************************************************; *The macro SIR calculates the observed and expected number of events from day i until day 730; %Macro SIR(i); Data COHORT_MAC ; set COHORT; Exit=min((entry+730),exit); entry=entry+&i; if diadate ne . then do; if diadate=>entry and diadate=0 then do; cl=0.5*cinv(0.025,2*obs)/exp; cu=0.5*cinv(0.975,2*(obs+1))/exp; end; else do; cl=0; cu=0.5*cinv(0.975,2*(obs+1))/exp; end; EXP=round(exp,0.01); CL=round(cl,0.01); CU=round(cu,0.01); Time=&i; run; *Adding calculated SIR for window i to dataset ALLSIR; Data ALLSIR; set SIR ALLSIR; run; %MEND; *************************************************************************************************** STEP 2 - REPEATED CALCULATIONS FOR DIFFERENT WINDOW SIZES First part of code calculates the expected and observed number of events from day 731 and onwards. This "bulk" calculation is then added to the expected and observed number of events calculated for the first 730 days where the window size is increased one day at the time. This calculation is performed once and then added to the calculations were one day is subtracted at the time. ***************************************************************************************************; %Macro doit; ***************************************************************************************************; Data FROM2YEARS; set COHORT; entry=entry+730; if diadate ne . then do; if diadate=>entry and diadate=