- /*0. 环境设置*/
- option missing = ' ';
- filename RawData "D:\作图20210812.xlsx ";
- /*1. 导入数据*/
- proc import datafile = RawData dbms = excel out = RawData replace;
- run;
- /*2. 执行生存分析*/
- /*2.1 计算各时点的生存率,并执行log-rank检验*/
- ods output ProductLimitEstimates = ProductLimitEstimates SurvivalPlot = SurvivalPlot HomTests = HomTests;
- proc lifetest data = RawData plots=(survival(atrisk=0 to 135 by 15));
- strata group;
- time time*_COL1(1);
- run;
- ods output close;
- data SurvivalPlot;
- set SurvivalPlot;
- /*获取删失数量*/
- do i = 1 to rec;
- set ProductLimitEstimates(keep=STRATUM time Censor rename=(STRATUM=TmpSTRATUM time=Tmptime))nobs=rec point=i;
- if StratumNum=TmpSTRATUM and time>=Tmptime then CountCensor = sum(CountCensor,Censor);
- end;
- if mod(time,15) = 0 then NumRiskAndCensor = cats(AtRisk,'(',CountCensor,')');
- if Survival then Survival = Survival * 100;
- if Censored then Censored = Censored * 100;
- run;
- data _null_;
- set HomTests;
- if Test = '对数秩' then call symputx('LogRank',cats(put(ProbChiSq,PValue6.3)));
- run;
- /*2.2 计算HR*/
- ods output HazardRatios = HazardRatios;
- proc phreg data = RawData;
- model time*_COL1(1) = group;
- hazardratio group;
- run;
- ods output close;
- data _null_;
- set HazardRatios;
- call symputx('HR',cats(put(HazardRatio,8.2)));
- call symputx('CI',catx('-',put(WaldLower,8.2),put(WaldUpper,8.2)));
- run;
- /*3. 对计算结果进行绘图呈现*/
- proc sgplot data = SurvivalPlot noborder nowall;
- styleattrs datacontrastcolors = (cx5b86c3 cxc7533b);
- step x = time y = Survival /group = StratumNum name = 'step';
- scatter x = time y = Censored /markerattrs = (symbol = plus);
- xaxistable NumRiskAndCensor /class = StratumNum colorgroup = StratumNum
- title = "Number at risk(Number censored)" titleattrs = (weight = bold);
- xaxis values=(0 to 135 by 15) display = (nolabel);
- yaxis values=(0 to 100 by 10);
- keylegend 'step' 'stat' /position = topright location = inside across = 1 noborder;
- inset "(*ESC*){unicode '0020'x}" "(*ESC*){unicode '0020'x}"
- "HR &HR. (95% CI &CI.), log rank P=&LogRank" /position = topright;
- label Survival = 'Disease free survival(%)';
- run;