** This clears the output and log windows and recalls the program; DM 'OUT;CLEAR;LOG;CLEAR;PGM;RECALL'; /* --------------------------------------------------------------- program: HAZARD.SAS xref: Cox & Oakes table 1.1 input: 6-MP DATA A output: CUMH? and HAZ? where ? is group number does: - demonstrate kernel hazard graphs and cumulative hazard plots --------------------------------------------------------------- */; **Creates a macro variable for the folder where all this project work is saved; %LET PATH=A:; OPTIONS PS=68 LS=120 PAGENO=1 NODATE ERRORS=3; ** automatically prints the date and time on the footnote of output; FOOTNOTE "HAZARD.SAS &SYSTIME &SYSDATE"; TITLE ' '; ** Designates file names to store the program, the output and the log; FILENAME PROGRAM "&PATH\PROG\HAZARD.SAS"; FILENAME LOG "&PATH\PROG\HAZARD.LOG"; FILENAME OUTPUT "&PATH\PROG\HAZARD.OUT"; ** Saves the program to above designated file; DM 'PGM; FILE PROGRAM REPLACE'; ** Designates file name where data is stored; FILENAME INF "&PATH\DISTRIB\6-MP.DAT"; ****************************************************; data A; infile INF; input time delta group; label time = 'Follow-up time (wks)' delta = 'Event: 0=censored 1=observed' group = 'Group: 0=control 1=drug' ; list; *lists input data in the log; run; ***************************************************; %include "&PATH\MACROS\HAZARD.MAC"; ** execute macro for each group; ** pass to the macro, TIME , DELTA (censored coded 0), GROUP (label for strata); ** GROUPNUM (number of the group you are running the macro for); ** DATA, BAND (bandwidth for the kernel hazard estimate); %HAZARD (TIME=TIME,DELTA=DELTA,GROUP=GROUP,DATA=A,GROUPNUM=0,BAND=3); %HAZARD (TIME=TIME,DELTA=DELTA,GROUP=GROUP,DATA=A,GROUPNUM=1,BAND=3); ** Macro produces datasets CUMH? and HAZ? where ? is the group number; ** Combine cumulative hazard estimates for all groups; DATA CUMH; SET CUMH1 CUMH0; RUN; PROC PRINT DATA=CUMH; RUN; ** Combine hazard estimates for all groups; DATA HAZ; SET HAZ1 HAZ0; RUN; ****************************************************************; **** Plot cum hazard and hazards; goptions reset=(axis, legend, pattern, symbol, title, footnote) graphrc interpol=join hpos=0 vpos=0 htext= ftext= ctext=blue target= gaccess= gsfmode= ; goptions device=WIN norotate ; ***for printing to the screen; *goptions device=HPLJS2 rotate; ***to send directly to printer; symbol1 c=DEFAULT i=SPLINE l=2 v=NONE ; symbol2 c=DEFAULT i=SPLINE l=1 v=NONE ; axis1 order=0 to 35 by 5 color=blue width=2.0 style=1 label=("Remission time in Weeks"); **make sure time axis includes the max time or graph will end abruptly; axis2 order=0 to 0.4 by .05 color=blue width=2.0 style=1 label=(""); **leave the label blank and let the rotated footnote be the label; legend1 position=( top left inside ) label = none value=( t=1 "Control" t=2 "6-mp" ) mode = protect ; Title1 height=2 'Kernel Estimator for Hazard Function (b=3)'; footnote angle=-90 rotate=90 ' Hazard'; ***footnote serves as label for the vertical axis; proc gplot data=WORK.HAZ ; plot LAMBDA * X = GROUP / haxis=axis1 vaxis=axis2 legend=legend1; run; quit; ********************* info specific to plotting Cum hazard****************************; symbol1 c=DEFAULT i=STEPSLJ l=2 v=NONE; symbol2 c=DEFAULT i=STEPSLJ l=1 v=NONE; *axis1 alread defined, leave the same; axis2 color=blue width=2.0 style=1 label=(""); **leave the label blank and let the rotated footnote be the label; legend1 position=( top left inside ) label = none value=(t=1 "Control" t=2 "6-mp" ) mode = protect; title1 height=2 'Cumulative Hazard Estimator'; footnote angle=-90 rotate=90 "Cumulative Hazard"; ***footnote serves as label for the vertical axis; proc gplot data=WORK.CUMH ; plot NELSON * TIME = GROUP / haxis=axis1 vaxis=axis2 legend=legend1; run; quit; ** Automatically saves contents of the output and log windows; DM 'LOG; FILE LOG REPLACE'; DM 'OUT; FILE OUTPUT REPLACE';