Vous êtes sur la page 1sur 11

%macro SurvivalTemplateRestore;

%global TitleText0 TitleText1 TitleText2 yOptions xOptions tips


tipl groups bandopts gridopts blockopts censored censorstr;
%let TitleText0 = METHOD " Survival Estimate prepared by Sid";
%let TitleText1 = &titletext0 " for " STRATUMID;
%let TitleText2 = &titletext0;
/* plural: Survival Estimates */
%let yOptions

%let xOptions
offsetmin=.05

%let tips

= label="Survival Probability by Sid" shortlabel="Survival"


linearopts=(viewmin=0 viewmax=1
tickvaluelist=(0.2 0.4 0.6 0.8 1.0));
= label="Treatment Analysis by Sid" shortlabel=XNAME
linearopts=(viewmax=MAXTIME tickvaluelist=XTICKVALS
tickvaluefitpolicy=XTICKVALFITPOL);

%let tipl

= rolename=(_tip1= ATRISK _tip2=EVENT)


tiplabel=(_tip1="Number at Risk" _tip2="Observed Events")
tip=(x y _tip1 _tip2);
= tiplabel=(y="Survival Probability");

%let groups

= group=STRATUM index=STRATUMNUM;

%let bandopts

= &groups modelname="Survival";

%let gridopts

= autoalign=(TOPRIGHT BOTTOMLEFT TOP BOTTOM)


border=true BackgroundColor=GraphWalls:Color Opaque=true;

%let blockopts
valuehalign=start

= repeatedvalues=true display=(label values)

valuefitpolicy=truncate labelposition=left
labelattrs=GRAPHVALUETEXT
valueattrs=GRAPHDATATEXT(size=7pt)
includemissingclass=false;
%let censored
%let censorstr

= markerattrs=(symbol=plus);
= "+ Censored";

%macro SurvivalTemplate;
%local outside _tmpnum;
proc template;
%do outside = 0 %to 1;
define statgraph Stat.Lifetest.Graphics.ProductLimitSurvival
%scan(2,2-&outside);
dynamic NStrata xName plotAtRisk %if %nrbquote(&censored) ne
%then plotCensored;
plotCL plotHW plotEP labelCL labelHW labelEP maxTime xtickVals
xtickValFitPol
rowWeights method StratumID classAtRisk plotBand plotTest
GroupName yMin
Transparency SecondTitle TestName pValue _byline_ _bytitle_
_byfootnote_;
BeginGraph;
if (NSTRATA=1)

if (EXISTS(STRATUMID)) entrytitle &titletext1;


else
entrytitle &titletext0;
endif;
%if not &outside %then if (PLOTATRISK);
entrytitle "With Number of Subjects at Risk" /
textattrs=GRAPHVALUETEXT;
%if not &outside %then %do; endif; %end;
%AtRiskLatticeStart
layout overlay / xaxisopts=(&xoptions) yaxisopts=(&yoptions);
%singlestratum
endlayout;
%AtRiskLatticeEnd
else
entrytitle &titletext2;
if (EXISTS(SECONDTITLE))
entrytitle SECONDTITLE / textattrs=GRAPHVALUETEXT;
endif;
%AtRiskLatticeStart
layout overlay / xaxisopts=(&xoptions) yaxisopts=(&yoptions);
%multiplestrata
endlayout;
%AtRiskLatticeEnd(%str(class=CLASSATRISK))
endif;
if (_BYTITLE_) entrytitle _BYLINE_ / textattrs=GRAPHVALUETEXT;
else if (_BYFOOTNOTE_) entryfootnote halign=left _BYLINE_; endif;
endif;
EndGraph;
end;
%end;
run;
%mend;
%macro entry_p;
if (PVALUE < .0001)
entry TESTNAME " p " eval (PUT(PVALUE, PVALUE6.4));
else
entry TESTNAME " p=" eval (PUT(PVALUE, PVALUE6.4));
endif;
%mend;
%macro SingleStratum;
if (PLOTHW=1 AND PLOTEP=0)
bandplot LimitUpper=HW_UCL LimitLower=HW_LCL x=TIME /
modelname="Survival" fillattrs=GRAPHCONFIDENCE
name="HW" legendlabel=LABELHW;
endif;
if (PLOTHW=0 AND PLOTEP=1)
bandplot LimitUpper=EP_UCL LimitLower=EP_LCL x=TIME /
modelname="Survival" fillattrs=GRAPHCONFIDENCE
name="EP" legendlabel=LABELEP;
endif;

if (PLOTHW=1 AND PLOTEP=1)


bandplot LimitUpper=HW_UCL LimitLower=HW_LCL x=TIME /
modelname="Survival" fillattrs=GRAPHDATA1 datatransparency=.55
name="HW" legendlabel=LABELHW;
bandplot LimitUpper=EP_UCL LimitLower=EP_LCL x=TIME /
modelname="Survival" fillattrs=GRAPHDATA2
datatransparency=.55 name="EP" legendlabel=LABELEP;
endif;
if (PLOTCL=1)
if (PLOTHW=1 OR PLOTEP=1)
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME /
modelname="Survival" display=(outline)
outlineattrs=GRAPHPREDICTIONLIMITS name="CL"
legendlabel=LABELCL;
else
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME /
modelname="Survival" fillattrs=GRAPHCONFIDENCE name="CL"
legendlabel=LABELCL;
endif;
endif;
stepplot y=SURVIVAL x=TIME / name="Survival" &tips
legendlabel="Survival";
if (PLOTCENSORED=1)
scatterplot y=CENSORED x=TIME / &censored &tipl
name="Censored" legendlabel="Censored";
endif;
if (PLOTCL=1 OR PLOTHW=1 OR PLOTEP=1)
discretelegend "Censored" "CL" "HW" "EP" / location=outside
halign=center;
else
if (PLOTCENSORED=1)
discretelegend "Censored" / location=inside
autoalign=(topright bottomleft);
endif;
endif;
%if not &outside %then %do;
if (PLOTATRISK=1)
innermargin / align=bottom;
blockplot x=TATRISK block=ATRISK / &blockopts;
endinnermargin;
endif;
%end;
%mend;
%macro MultipleStrata;
if (PLOTHW)
bandplot LimitUpper=HW_UCL LimitLower=HW_LCL x=TIME / &bandopts
datatransparency=Transparency;
endif;
if (PLOTEP)
bandplot LimitUpper=EP_UCL LimitLower=EP_LCL x=TIME / &bandopts
datatransparency=Transparency;
endif;
if (PLOTCL)

if (PLOTBAND)
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME / &bandopts
display=(outline);
else
bandplot LimitUpper=SDF_UCL LimitLower=SDF_LCL x=TIME / &bandopts
datatransparency=Transparency;
endif;
endif;
stepplot y=SURVIVAL x=TIME / &groups name="Survival" &tips;
if (PLOTCENSORED)
scatterplot y=CENSORED x=TIME / &groups &tipl &censored;
endif;
%if not &outside %then %do;
if (PLOTATRISK=1)
innermargin / align=bottom;
blockplot x=TATRISK block=ATRISK / class=CLASSATRISK
&blockopts;
endinnermargin;
endif;
%end;
DiscreteLegend "Survival" / title=GROUPNAME location=outside;
if (PLOTCENSORED)
if (PLOTTEST)
layout gridded / rows=2 &gridopts;
entry &censorstr;
%entry_p
endlayout;
else
layout gridded / rows=1 &gridopts;
entry &censorstr;
endlayout;
endif;
else
if (PLOTTEST)
layout gridded / rows=1 &gridopts;
%entry_p
endlayout;
endif;
endif;
%mend;
%macro AtRiskLatticeStart;
%if &outside %then %do;
layout lattice / rows=2 rowweights=ROWWEIGHTS
columndatarange=union rowgutter=10;
cell;
%end;
%mend;
%macro AtRiskLatticeEnd(class);
%if &outside %then %do;
endcell;

cell;
layout overlay / walldisplay=none xaxisopts=(display=none);
blockplot x=TATRISK block=ATRISK / &class &blockopts;
endlayout;
endcell;
endlayout;
%end;
%mend;
%SurvivalTemplate
%mend;

%SurvivalTemplateRestore
libname siddy 'C:\Users\sidd1937\Desktop\Sid-Lifetest';
run;
data siddy.ADDEATH30;
label TRTP = "Planned Treatment"
AVAL = "Analysis Value" /*
CNSR = "Censor";
input TRTP $ AVAL CNSR @@;
datalines;
A 52
0
A 825
1
C
B 279
0
B 826
1
B
C 1057 1
C 793
1
B
C 470
1
A 251
0
C
B 350
1
B 746
1
A
A 163
0
C 735
1
B
C 889
1
C 932
1
C
A 155
1
A 708
1
A
B 114
0
B 704
1
C
A 816
1
A 100
0
C
C 959
1
C 675
1
C
B 33
0
B 645
1
A
C 150
1
A 638
1
B
B 686
1
B 638
1
A
A 659
1
A 133
0
C
C 70
1
A 592
1
B
A 1007 1
C 594
1
C
B 964
1
C 582
1
B
C 962
1
B 282
1
C
B 961
1
C 521
1
A
C 1000 1
B 9
0
A
A 910
1
C 1107 1
C
C 89
1
A 1111 1
C
B 442
0
B 92
0
B
B 532
0
A 1062 1
A
C 136
1
C 154
1
C
A 839
1
B 1076 1
A
A 815
1
A 1037 1
B
C 803
1
C 16
0
A
A 28
0
A 1004 1
B
C 1299 1
B 79
1
C

"Days to Death" */

693
531
1048
830
122
699
773
547
1044
953
960
56
905
872
360
112
7
1024
873
268
678
1071
701
1079
903
845
834
832
630
1020
170

1
1
1
1
0
1
0
1
1
1
0
0
1
0
1
1
1
0
1
0
1
0
1
1
1
1
0
1
1
1
1

C
B
A
B
B
B
C
A
A
C
A
A
B
C
A
B
B
A
C
A
C
A
B
A
C
B
A
C
B
A
B

981
15
925
668
825
771
767
462
702
632
51
980
341
1347
907
882
361
540
1294
657
989
971
364
93
792
52
589
1120
546
75
945

1
1
1
0
1
0
1
0
0
1
1
0
0
1
0
0
1
0
1
1
0
1
0
1
1
1
1
1
1
1
1

B 1056
B 1026
A 1022
C 127
A 1209
C 5
B 954
A 952
C 23
B 946
B 945
C 931
A 103
C 910
B 907
A 8
C 11
A 868
B 842
;
run;

1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
0
1
1
1

B
C
A
B
C
A
B
C
B
A
C
B
C
A
B
A
C
B
A

947
128
915
745
154
833
60
776
776
752
722
2
1036
760
896
895
446
774
268

1
0
1
0
1
1
0
1
1
1
1
1
1
1
1
1
0
1
0

A
B
A
C
B
A
C
B
A
C
A
B
C
B
A
C
C
A
B

1015
940
427
834
723
705
705
680
667
1076
630
583
599
563
544
525
522
500
505

1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

A
C
A
B
C
B
A
C
C
A
B
A
C
B
A
C
C
A
B

190
1270
177
752
1244
49
528
88
155
380
61
282
17
347
404
740
254
27
505

0
1
0
1
1
1
1
1
1
0
0
0
1
0
0
1
1
1
0

proc format;
value $trtp
"A" = "Placebo"
"B" = "Old Drug"
"C" = "New Drug";
run;
ods _all_ close;
ods pdf file="C:\Users\sidd1937\Desktop\Sid-Lifetest\siddu30.pdf";
ods graphics on;
Proc lifetest data= siddy.ADDEATH plots=survival(cb=hw test atrisk(maxlen=15
outside));
time aval*cnsr(1);
strata trtp;
format trtp $trtp.;
run;
ods graphics off;
ods pdf close;
Proc template;
delete Stat.Lifetest.Graphics.ProductLimitSurvival /Store=SASUSER.TEMPLAT;
delete Stat.Lifetest.Graphics.ProductLimitSurvival2/Store=SASUSER.TEMPLAT;
run;

Wrong code
data ADDEATH6;
label TRTP = "Planned Treatment"
AVAL = "Analysis Value" /*
CNSR = "Censor";
input TRTP $ AVAL CNSR @@;
datalines;
A 52
0
A 825
1
C
B 279
0
B 826
1
B
C 1057 1
C 793
1
B
C 470
1
A 251
0
C
B 350
1
B 746
1
A
A 163
0
C 735
1
B
C 889
1
C 932
1
C
A 155
1
A 708
1
A
B 114
0
B 704
1
C
A 816
1
A 100
0
C
C 959
1
C 675
1
C
B 33
0
B 645
1
A
C 150
1
A 638
1
B
B 686
1
B 638
1
A
A 659
1
A 133
0
C
C 70
1
A 592
1
B
A 1007 1
C 594
1
C
B 964
1
C 582
1
B
C 962
1
B 282
1
C
B 961
1
C 521
1
A
C 1000 1
B 9
0
A
A 910
1
C 1107 1
C
C 89
1
A 1111 1
C
B 442
0
B 92
0
B
B 532
0
A 1062 1
A
C 136
1
C 154
1
C
A 839
1
B 1076 1
A
A 815
1
A 1037 1
B
C 803
1
C 16
0
A
A 28
0
A 1004 1
B
C 1299 1
B 79
1
C
B 1056 1
B 947
1
A
B 1026 1
C 128
0
B
A 1022 0
A 915
1
A
C 127
1
B 745
0
C
A 1209 1
C 154
1
B
C 5
1
A 833
1
A
B 954
1
B 60
0
C
A 952
1
C 776
1
B
C 23
1
B 776
1
A
B 946
1
A 752
1
C

"Days to Death" */

693
531
1048
830
122
699
773
547
1044
953
960
56
905
872
360
112
7
1024
873
268
678
1071
701
1079
903
845
834
832
630
1020
170
1015
940
427
834
723
705
705
680
667
1076

1
1
1
1
0
1
0
1
1
1
0
0
1
0
1
1
1
0
1
0
1
0
1
1
1
1
0
1
1
1
1
1
1
0
1
1
1
1
1
1
1

C
B
A
B
B
B
C
A
A
C
A
A
B
C
A
B
B
A
C
A
C
A
B
A
C
B
A
C
B
A
B
A
C
A
B
C
B
A
C
C
A

981
15
925
668
825
771
767
462
702
632
51
980
341
1347
907
882
361
540
1294
657
989
971
364
93
792
52
589
1120
546
75
945
190
1270
177
752
1244
49
528
88
155
380

1
1
1
0
1
0
1
0
0
1
1
0
0
1
0
0
1
0
1
1
0
1
0
1
1
1
1
1
1
1
1
0
1
0
1
1
1
1
1
1
0

B 945
C 931
A 103
C 910
B 907
A 8
C 11
A 868
B 842
;
run;

1
1
0
1
1
0
1
1
1

C
B
C
A
B
A
C
B
A

722
2
1036
760
896
895
446
774
268

1
1
1
1
1
1
0
1
0

A
B
C
B
A
C
C
A
B

630
583
599
563
544
525
522
500
505

1
1
1
1
1
1
1
1
1

B
A
C
B
A
C
C
A
B

61
282
17
347
404
740
254
27
505

0
0
1
0
0
1
1
1
0

proc format;
value $trtp
"A" = "Placebo"
"B" = "Old Drug"
"C" = "New Drug";

/*data annotatesid1;
length function color $8;
retain xsys ysys '2' hsys '3';
function='label'; color='black'; x=23+2; y=70+5; text='Longest';
output;
run; */
ods graphics;
ods exclude all;
ods output survivalplot=survivalplot;
Proc lifetest data= ADDEATH plots=survival;
time aval*cnsr(1);
strata trtp;
run;
ods output close;
Data survivalplot;
set survivalplot;
month=aval/30.417;
run;

ods html style=htmlbluecml image_dpi=300;


proc sgplot data=survivalplot;
title "Kmplot prepared by Sid";
label TRTP='Treatment by Sid';
format TRTP $trtp.;
step x=month y=survival/group=trtp;
xaxis values=(0 to 48 by 6) minorcount=1;
label ='Months from Rand';

yaxis values=(0 to 1 by 0.1) minorcount=1;


label ='Survival probability by Sid';
run;
ods graphics off;
ods html close;
/*
axis1 order=0 to 80 by 10 minor=(number=1) label=(angle=90 "LENGTH");
axis2 order=0 to 30 by 5 minor=(number=1) label=("WIDTH");
symbol Interpol=none value="X" color=black height=2;
plot petallen*petalwid / vaxis=axis1
haxis=axis2
noframe
annotate=annotate_data_ex1;
run;
quit; */

scatter
libname siddy 'C:\Users\sidd1937\Desktop\Sid-Lifetest';
run;
data siddy.ADLB2;
label USUBJID = "Unique Subject Identifier"
PARAMCD = "Parameter Code"
BASE
= "Baseline Value"
AVAL
= "Analysis Value"
TRTP
= "Planned Treatment";
input USUBJID $ PARAMCD $ AVAL BASE TRTP $ @@;
datalines;
101 HCT 35.0 31.0 a
102 HCT 40.2 30.0 a
103 HCT 42.0 42.4 b
104 HCT 41.2 41.4 b
105 HCT 35.0 33.3 a
106 HCT 34.3 34.3 a
107 HCT 30.3 44.0 b
108 HCT 34.2 42.0 b
109 HCT 40.0 41.1 b
110 HCT 41.0 42.1 b
111 HCT 33.3 33.8 a
112 HCT 34.0 31.0 a
113 HCT 34.0 41.0 b
114 HCT 34.0 40.0 b
115 HCT 37.2 35.2 a
116 HCT 39.3 36.2 a
117 HCT 36.3 38.3 b
118 HCT 37.4 37.3 b
119 HCT 44.2 34.3 a
120 HCT 42.2 36.5 a
;
run;
ods html style=htmlbluecml image_dpi=300;
ods graphics on;
proc sgplot data=siddy.adlb;
scatter x=AVAL y=BASE/group=TRTP;
xaxis values=(30 35 40 45) microcount=4;
yaxis values=(30 35 40 45) microcount=4;

lineparm x=30 y=30 slope=1;


title1 'Sid is preparing this plot';
title2 'at visit 3';
run;
ods graphics off;
ods html close;

line
libname siddy 'C:\Users\sidd1937\Desktop\Sid-Lifetest';
run;
data siddy.ADEFF;
label AVAL
= "Analysis Value"
AVISITN = "Analysis Visit (N)"
TRTPN
= "Planned Treatment (N)";
input TRTPN AVISITN AVAL @@;
datalines;
1 0 9.40
2 0 9.55
1 1 9.35
2 1 9.45
1 2 8.22
2 2 8.78
1 3 6.33
2 3 8.23
1 4 4.00
2 4 7.77
1 5 2.22
2 5 4.46
1 6 1.44
2 6 2.00
1 7 1.13
2 7 1.86
1 8 0.55
2 8 1.44
1 9 0.67
2 9 1.33
1 10 0.45
2 10 1.01
;
run;
proc format;
value avisitn
0 = "Baseline"
1 = "Day 1"
2 = "Day 2"
3 = "Day 3"
4 = "Day 4"
5 = "Day 5"
6 = "Day 6"
7 = "Day 7"
8 = "Day 8"
9 = "Day 9"
10 = "Day 10";
value trtpn
1 = "Super Drug"
2 = "Old Drug";
run;

ods html image_dpi=300;


ods graphics;
proc sgplot data= siddy.ADEFF;
series x=avisitn y=aval/group=trtpn markers;
refline 1/axis=x;
yaxis values=(0 to 10 by 1) label='Mean clinical response conducted by Sid';
xaxis values=(0 to 10 by 1) label="Visits analyzed by Sid";
keylegend/location=inside position=topright;
format avistn avisitn.;
format trtpn trtpn.;
title 'Mean clinical response by Visit';
run;
ods html close;

Vous aimerez peut-être aussi