SAS

您所在的位置:网站首页 一套绘图工具 SAS

SAS

2024-07-11 11:13| 来源: 网络整理| 查看: 265

年前,小编打算写一套SAS绘图的宏程序,于是在朋友圈发了个“调查问卷”,询问了大家临床编程中常遇见的图形。经过漫长的积累与等待(究其原因还是太懒了),本文孕育与诞生了,小编将在本文及后续推文中汇总并分享一些常见的SAS绘图程序及技巧。

图形类型

折线图

散点图

条形图

箱体图

蜘蛛图

泳道图

瀑布图

生存图

小编最初的想法是将这些图形的绘制写成宏,然后分享/出售

,日前,看到了《药物临床试验数据递交指导原则(征求意见稿).doc》正文114行的“尤其应避免大型宏程序的嵌套”,所以写宏的计划暂时夭折了。所以呀,今天要分享的内容不含大型宏程序。

折线图

首先是最基础的折线图,折线图的应有也是十分广泛的,譬如:药时曲线等均是临床试验中折线图绘制的典型例子。关于这部分小编也是在历史文章写过的,如有兴趣可在本文阅读完后,在此点击进行阅读(药时(一)、药时(二)),当然这是几年前的文章了,文中不乏有漏洞或程序冗杂之处。如有需要小编后来多次更新的最新相关程序,可私下联系。

SGPLOT

GTL

代码语言:javascript复制 proc format ; value GROUPfmt 1='高剂量组' 2='中剂量组' 3='低剂量组' 4='安慰剂组'; run; data adrs; do i=1 to 20; *模拟受试者; SUBJID=put(i,z3.); *模拟组别; ARMCD=mod(i,4)+1; ARM=put(ARMCD,GROUPfmt.); do DY=1 to 4; aval=int(ranuni(1)*20)*int(ranuni(0)*10); output; end; end; run; proc sort data=adrs out=adrs ;by ARMCD ARM DY ; ;quit; proc means data = adrs noprint alpha=0.05; by ARMCD ARM DY; var aval; output out=_runtemp_s1 n = n mean = mean q1=q1 q3=q3 std=std median=median nmiss=nmiss min=min max=max lclm=lclm_ uclm=uclm_; run; ods rtf file="&runsetup.\折线图测试结果.rtf" style=threelines_setup startpage=yes; ODS graphics on /width=18cm height=10cm noborder ; ods rtf nogtitle nogfootnote;/*避免title footnote出现在title中*/ title1 j= l "官网:https://www.sas-pharma.com" j= r "作者:Setup"; title2 j= l"微信号:xiaocgn" j= r"日期:&date1."; footnote j= l "折线图(V1.0)" j= r "欢迎关注公众号"; data Setup; length value FillColor LineColor MARKERCOLOR MARKERSYMBOL LINEPATTERN $30; Id='Setup'; Value="1"; FillColor='Red'; LineColor='Red';LINEPATTERN='solid';LINETHICKNESS=1;MARKERSYMBOL='circlefilled'; MARKERCOLOR='Red'; output; Id='Setup'; Value="2"; FillColor='blue'; LineColor='blue'; LINEPATTERN='solid';LINETHICKNESS=1;MARKERSYMBOL='circlefilled'; MARKERCOLOR='blue'; output; Id='Setup'; Value="3"; FillColor='Green'; LineColor='Green';LINEPATTERN='solid';LINETHICKNESS=1;MARKERSYMBOL='circlefilled'; MARKERCOLOR='Green'; output; Id='Setup'; Value="4"; FillColor='Orange'; LineColor='Orange';LINEPATTERN='solid';LINETHICKNESS=1;MARKERSYMBOL='circlefilled'; MARKERCOLOR='Orange'; output; run; *图中画标题:legenditem; proc sgplot data=_runtemp_s1 dattrmap=Setup; series x=DY y=mean/ group=ARMCD name='L2' lineattrs=(thickness=1) markers ATTRID=Setup ; legenditem type=markerline name="S1" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=red symbol=circlefilled) lineattrs=(color=red) label="高剂量组" outlineattrs=(color=white); legenditem type=markerline name="S2" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=blue symbol=circlefilled) lineattrs=(color=blue) label="中剂量组" outlineattrs=(color=white); legenditem type=markerline name="S3" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=green symbol=circlefilled) lineattrs=(color=green) label="低剂量组" outlineattrs=(color=white); legenditem type=markerline name="S4" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=Orange symbol=circlefilled) lineattrs=(color=Orange) label="安慰剂组" outlineattrs=(color=white); /*设置:设置图例*/ keylegend 'S1' 'S2' 'S3' 'S4'/ title="" location= inside position=TOPRIGHT noborder across=1 titleattrs=(color=black family="Times New Roman/宋体" size=10) valueattrs=(color=black family="Times New Roman/宋体" size=10) sortorder=REVERSEAUTO ; legenditem type=TEXT name="S5" /TEXT="Figure xxx.xxx.x.x Series Plot " TEXTATTRS=(color=black family="Times New Roman/宋体" size=10); keylegend 'S5' / title=" " location= outside position=top noborder down=1 titleattrs=(color=black family="Times New Roman/宋体" size=10) valueattrs=(color=black family="Times New Roman/宋体" size=10) ; ; /*设置:坐标*/ xaxis label="X轴" values=( 1 2 3 4) valuesdisplay=("基线" "治疗第2周" "治疗第4周" "随访期") valueattrs=(color=black family="times new roman/宋体" size=10) labelattrs=(color=black family="Times New Roman/宋体" size=10) fitpolicy=none valuesrotate=diagonal2 ; *刻度值旋转:ROTATE 旋转反向:VALUESROTATE:diagonal | diagonal2 | vertical ; yaxis label="Y轴" values=(0 to 120 by 20) valueattrs=(color=black family="times new roman/宋体" size=10) labelattrs=(color=black family="Times New Roman/宋体" size=10) fitpolicy=none; run; ods graphics /outputfmt=JPEG; proc template; define statgraph setup; begingraph/ border=false backgroundcolor=white; entryfootnote halign=center "Figure xxx.xxx.x.x Series Plot "/ textattrs=(color=black family="times new roman/宋体" size=7); /* entrytitle halign=left "&&ffootnote&ms." / textattrs=(color=black family="times new roman/宋体" size=7);*/ discreteattrmap name="temp1" / ignorecase=true; value "1" /markerattrs=GraphData1(color=red symbol=circlefilled ) lineattrs=GraphData1(color=red pattern=solid ) fillattrs=GraphData1(color=red ); value "2" /markerattrs=GraphData1(color=blue symbol=circlefilled ) lineattrs=GraphData1(color=blue pattern=solid) fillattrs=GraphData1(color=blue ); value "3" /markerattrs=GraphData1(color=green symbol=circlefilled) lineattrs=GraphData1(color=green pattern=solid) fillattrs=GraphData1(color=green ); value "4" /markerattrs=GraphData1(color=Orange symbol=circlefilled) lineattrs=GraphData1(color=Orange pattern=solid) fillattrs=GraphData1(color=Orange ); enddiscreteattrmap; discreteattrvar attrvar=markers1 var=ARMCD attrmap="temp1"; legenditem type=markerline name="S1" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=red symbol=circlefilled) lineattrs=(color=red) label="高剂量组" outlineattrs=(color=white); legenditem type=markerline name="S2" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=blue symbol=circlefilled) lineattrs=(color=blue) label="中剂量组" outlineattrs=(color=white); legenditem type=markerline name="S3" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=green symbol=circlefilled) lineattrs=(color=green) label="低剂量组" outlineattrs=(color=white); legenditem type=markerline name="S4" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=Orange symbol=circlefilled) lineattrs=(color=Orange) label="安慰剂组" outlineattrs=(color=white); layout overlay //* walldisplay=none*/ cycleattrs=true yaxisopts=(gridDisplay=off LABEL="Y轴" labelattrs=(size=7pt family="Times New Roman/宋体") LABELSPLITCHAR="$" LABELFITPOLICY=SPLITALWAYS tickvalueattrs=( size=7pt family="Times New Roman/宋体") linearopts=(tickvaluelist=(0 20 40 60 80 100 120) tickvaluefitpolicy=none tickvaluepriority=true )) xaxisopts=(display=(ticks tickvalues line label) gridDisplay=off label="X轴" labelattrs=(size=7pt family="Times New Roman/宋体") tickvalueattrs=( size=7pt family="Times New Roman/宋体") linearopts=(tickvaluelist=( 1 2 3 4 ) tickdisplaylist=("基线" "治疗第2周" "治疗第4周" "随访期") tickvaluefitpolicy=none tickvaluepriority=true )) ; seriesplot x=DY y=mean/ group=markers1 name="series1" lineattrs=(thickness=1) display=(markers) markercolorgroup=markers1 markerattrs=(symbol=circlefilled) linecolorgroup=markers1 lineattrs=(pattern=solid) ; discretelegend "S1" "S2" "S3" 'S4'/ border=false location=inside halign=right valign=top across=1 title="" titleattrs=GraphValueText(color=black family="Times New Roman/宋体" size=10pt); endlayout; endgraph; end; run; proc sgrender data=_runtemp_s1 template=setup; run; ; ; ods rtf close;

代码如上,分别采取PROC SGPLOT与 GTL俩种绘图方式。数据均是模拟随机产生的。关于代码中的语法,此处不做介绍,可私下与小编交流或查看SAS帮助文档。

代码下载链接:

https://www.sas-pharma.com/code/seriesplot.txt

散点图

散点图也是基础图形之一,在临床统计绘图编程中,散点图常与其他图形一起组成复合图形,譬如:泳道图上的标记符等,相关的例子很多。

SGPLOT

GTL

代码语言:javascript复制proc format ; value GROUPfmt 1='高剂量组' 2='中剂量组' 3='低剂量组' 4='安慰剂组'; run; data adrs; do i=1 to 20; *模拟受试者; SUBJID=put(i,z3.); *模拟组别; ARMCD=mod(i,4)+1; ARM=put(ARMCD,GROUPfmt.); do DY=1 to 4; aval=int(ranuni(1)*20)*int(ranuni(0)*10); output; end; end; run; proc sort data=adrs out=adrs ;by ARMCD ARM DY ; ;quit; proc means data = adrs noprint alpha=0.05; by ARMCD ARM DY; var aval; output out=_runtemp_s1 n = n mean = mean q1=q1 q3=q3 std=std median=median nmiss=nmiss min=min max=max lclm=lclm_ uclm=uclm_; run; data _runtemp_s1; set _runtemp_s1; upperstd=mean+std; lowerstd=mean-std; run; ods rtf file="&runsetup.\散点图测试结果.rtf" style=threelines_setup startpage=yes; ODS graphics on /width=18cm height=10cm noborder ; ods rtf nogtitle nogfootnote;/*避免title footnote出现在title中*/ title1 j= l "官网:https://www.sas-pharma.com" j= r "作者:Setup"; title2 j= l"微信号:xiaocgn" j= r"日期:&date1."; footnote j= l "散点图(V1.0)" j= r "欢迎关注公众号"; data Setup; length value FillColor LineColor MARKERCOLOR MARKERSYMBOL LINEPATTERN $30; Id='Setup'; Value="1"; FillColor='Red'; LineColor='Red';LINEPATTERN='solid';LINETHICKNESS=1;MARKERSYMBOL='triangleright'; MARKERCOLOR='Red'; output; Id='Setup'; Value="2"; FillColor='blue'; LineColor='blue'; LINEPATTERN='solid';LINETHICKNESS=1;MARKERSYMBOL='triangle'; MARKERCOLOR='blue'; output; Id='Setup'; Value="3"; FillColor='Green'; LineColor='Green';LINEPATTERN='solid';LINETHICKNESS=1;MARKERSYMBOL='triangledown'; MARKERCOLOR='Green'; output; Id='Setup'; Value="4"; FillColor='Orange'; LineColor='Orange';LINEPATTERN='solid';LINETHICKNESS=1;MARKERSYMBOL='triangleleft'; MARKERCOLOR='Orange'; output; run; *图中画标题:legenditem; proc sgplot data=_runtemp_s1 dattrmap=Setup; scatter x=DY y=mean/ group=ARMCD yerrorupper =upperstd yerrorlower=lowerstd ATTRID=Setup; legenditem type=marker name="S1" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=red symbol=triangleright) lineattrs=(color=red) label="高剂量组" outlineattrs=(color=white); legenditem type=marker name="S2" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=blue symbol=triangle) lineattrs=(color=blue) label="中剂量组" outlineattrs=(color=white); legenditem type=marker name="S3" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=green symbol=triangledown) lineattrs=(color=green) label="低剂量组" outlineattrs=(color=white); legenditem type=marker name="S4" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=Orange symbol=triangleleft) lineattrs=(color=Orange) label="安慰剂组" outlineattrs=(color=white); /*设置:设置图例*/ keylegend 'S1' 'S2' 'S3' 'S4'/ title="" location= inside position=TOPRIGHT noborder across=1 titleattrs=(color=black family="Times New Roman/宋体" size=10) valueattrs=(color=black family="Times New Roman/宋体" size=10) sortorder=REVERSEAUTO ; legenditem type=TEXT name="S5" /TEXT="Figure xxx.xxx.x.x scatter Plot " TEXTATTRS=(color=black family="Times New Roman/宋体" size=10); keylegend 'S5' / title=" " location= outside position=top noborder down=1 titleattrs=(color=black family="Times New Roman/宋体" size=10) valueattrs=(color=black family="Times New Roman/宋体" size=10) ; ; /*设置:坐标*/ xaxis label="X轴" values=( 1 2 3 4) valuesdisplay=("基线" "治疗第2周" "治疗第4周" "随访期") valueattrs=(color=black family="times new roman/宋体" size=10) labelattrs=(color=black family="Times New Roman/宋体" size=10) fitpolicy=none valuesrotate=diagonal2 ; *刻度值旋转:ROTATE 旋转反向:VALUESROTATE:diagonal | diagonal2 | vertical ; yaxis label="Y轴" values=(-40 to 140 by 20) valueattrs=(color=black family="times new roman/宋体" size=10) labelattrs=(color=black family="Times New Roman/宋体" size=10) fitpolicy=none; run; ods graphics /outputfmt=JPEG; proc template; define statgraph setup; begingraph/ border=false backgroundcolor=white; entryfootnote halign=center "Figure xxx.xxx.x.x scatter Plot "/ textattrs=(color=black family="times new roman/宋体" size=7); /* entrytitle halign=left "&&ffootnote&ms." / textattrs=(color=black family="times new roman/宋体" size=7);*/ discreteattrmap name="temp1" / ignorecase=true; value "1" /markerattrs=GraphData1(color=red symbol=triangleright ) lineattrs=GraphData1(color=red pattern=solid ) fillattrs=GraphData1(color=red ); value "2" /markerattrs=GraphData1(color=blue symbol=triangle ) lineattrs=GraphData1(color=blue pattern=solid) fillattrs=GraphData1(color=blue ); value "3" /markerattrs=GraphData1(color=green symbol=triangledown) lineattrs=GraphData1(color=green pattern=solid) fillattrs=GraphData1(color=green ); value "4" /markerattrs=GraphData1(color=Orange symbol=triangleleft) lineattrs=GraphData1(color=Orange pattern=solid) fillattrs=GraphData1(color=Orange ); enddiscreteattrmap; discreteattrvar attrvar=markers1 var=ARMCD attrmap="temp1"; legenditem type=marker name="S1" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=red symbol=triangleright) lineattrs=(color=red) label="高剂量组" outlineattrs=(color=white); legenditem type=marker name="S2" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=blue symbol=triangle) lineattrs=(color=blue) label="中剂量组" outlineattrs=(color=white); legenditem type=marker name="S3" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=green symbol=triangledown) lineattrs=(color=green) label="低剂量组" outlineattrs=(color=white); legenditem type=marker name="S4" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=Orange symbol=triangleleft) lineattrs=(color=Orange) label="安慰剂组" outlineattrs=(color=white); layout overlay //* walldisplay=none*/ cycleattrs=true yaxisopts=(gridDisplay=off LABEL="Y轴" labelattrs=(size=7pt family="Times New Roman/宋体") LABELSPLITCHAR="$" LABELFITPOLICY=SPLITALWAYS tickvalueattrs=( size=7pt family="Times New Roman/宋体") linearopts=(tickvaluelist=(-40 -20 0 20 40 60 80 100 120 140) tickvaluefitpolicy=none tickvaluepriority=true )) xaxisopts=(display=(ticks tickvalues line label) gridDisplay=off label="X轴" labelattrs=(size=7pt family="Times New Roman/宋体") tickvalueattrs=( size=7pt family="Times New Roman/宋体") linearopts=(tickvaluelist=( 1 2 3 4 ) tickdisplaylist=("基线" "治疗第2周" "治疗第4周" "随访期") tickvaluefitpolicy=none tickvaluepriority=true )) ; scatterplot x=DY y=mean/ group=markers1 yerrorupper =upperstd yerrorlower=lowerstd ; discretelegend "S1" "S2" "S3" 'S4'/ border=false location=inside halign=right valign=top across=1 title="" titleattrs=GraphValueText(color=black family="Times New Roman/宋体" size=10pt); endlayout; endgraph; end; run; proc sgrender data=_runtemp_s1 template=setup; run; ; ; ods rtf close;

代码如上,分别采取PROC SGPLOT与 GTL俩种绘图方式。数据均是模拟随机产生的。关于代码中的语法,此处不做介绍,可私下与小编交流或查看SAS帮助文档。

代码下载链接:

https://www.sas-pharma.com/code/scatterplot.txt

条形图

关于条形小编以前也发过相关推送,譬如:譬如堆积条形图的绘制,如有兴趣可在本文阅读完后,在此点击进行阅读(堆积条形图的绘制),条形图也是基础图形之一,可与其他图形组合使用,生成瀑布图、泳道图等等。

SGPLOT

GTL

代码语言:javascript复制 proc format ; value GROUPfmt 1='高剂量组' 2='中剂量组' 3='低剂量组' 4='安慰剂组'; run; data adrs; do i=1 to 20; *模拟受试者; SUBJID=put(i,z3.); *模拟组别; ARMCD=mod(i,4)+1; ARM=put(ARMCD,GROUPfmt.); *模拟研究时长; DY01=ranuni(0)*20; output; end; drop I; run; data _null_; call symput("date",left(put("&sysdate"d,yymmdd10.))); call symput("date1",left(compress(put("&sysdate"d,yymmdd10.),"-"," "))); run; ods rtf file="&runsetup.\条形测试结果.rtf" style=threelines_setup startpage=no; ODS graphics on /width=18cm height=10cm noborder ; ods rtf nogtitle nogfootnote;/*避免title footnote出现在title中*/ title1 j= l "官网:https://www.sas-pharma.com" j= r "作者:Setup"; title2 j= l"微信号:xiaocgn" j= r"日期:&date1."; footnote j= l "条形图(V1.0)" j= r "欢迎关注公众号"; * DATTRMAP 数据集变量介绍 FILLCOLOR:填充颜色 FILLTRANSPARENCY:透明度 ID :指定标识 与plot语句中的 attrid=参数对应 LINECOLOR :线条颜色 LINEPATTERN:线条类型 LINETHICKNESS:线条粗细 MARKERCOLOR:标记符号颜色 MARKERSIZE:标记符号大小 MARKERSYMBOL:标记符号名称 MARKERTRANSPARENCY:标记符号透明度 VALUE:指定对应group组别的值; data Setup; length value FillColor LineColor $30; Id='Setup'; Value="1"; FillColor='Red'; LineColor='Black'; output; Id='Setup'; Value="2"; FillColor='blue'; LineColor='Black'; output; Id='Setup'; Value="3"; FillColor='Green'; LineColor='Black'; output; Id='Setup'; Value="4"; FillColor='Orange'; LineColor='Black'; output; run; *图中画标题:legenditem; proc sort data=adrs out= adrs sortseq=linguistic(numeric_collation=on);by subjid ;quit; proc sgplot data=adrs noborder dattrmap=Setup; hbarparm category=subjid response=DY01 / group=ARMCD GROUPORDER=DATA name='L2' nooutline transparency=0.3 attrid=Setup ; legenditem type=FILL name="S1" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) lineattrs=(color=red) FILLATTRS=(color=red transparency = 0.3) label="高剂量组" outlineattrs=(color=white); legenditem type=FILL name="S2" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) lineattrs=(color=blue) FILLATTRS=(color=blue transparency = 0.3) label="中剂量组" outlineattrs=(color=white); legenditem type=FILL name="S3" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) lineattrs=(color=green) FILLATTRS=(color=green transparency = 0.3) label="低剂量组" outlineattrs=(color=white); legenditem type=FILL name="S4" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) lineattrs=(color=Orange) FILLATTRS=(color=Orange transparency = 0.3) label="安慰剂组" outlineattrs=(color=white); /*设置:设置图例*/ keylegend 'S1' 'S2' 'S3' 'S4' / title="" location= outside position=BOTTOM noborder down=4 titleattrs=(color=black family="Times New Roman/宋体" size=10) valueattrs=(color=black family="Times New Roman/宋体" size=10) ; legenditem type=TEXT name="S10" /TEXT="Figure xxx.xxx.x.x barchart Plot " TEXTATTRS=(color=black family="Times New Roman/宋体" size=10); /*在图中绘制标题:*/ keylegend 'S10' / title=" " location= outside position=top noborder down=1 titleattrs=(color=black family="Times New Roman/宋体" size=10) valueattrs=(color=black family="Times New Roman/宋体" size=10) ; /*设置:坐标*/ xaxis label="Months since first dose of study drug" values=(0 to 26 by 2) valueattrs=(color=black family="times new roman/宋体" size=10) labelattrs=(color=black family="Times New Roman/宋体" size=10) fitpolicy=none valuesrotate=diagonal2 ; *刻度值旋转:ROTATE 旋转反向:VALUESROTATE:diagonal | diagonal2 | vertical ; yaxis display=(noticks noline nolabel) reverse valueattrs=(color=black family="times new roman/宋体" size=10) labelattrs=(color=black family="Times New Roman/宋体" size=10) fitpolicy=none; run; proc template; define statgraph setup; begingraph / backgroundcolor=CXFFFFFF dataskin=none; entrytitle halign=center "Figure xxx.xxx.x.x barchart Plot" /textattrs=(color=black family="Times New Roman/宋体" size=9); discreteattrmap name="temp1" / ignorecase=true; value "1" /markerattrs=GraphData1(color=red symbol=circlefilled ) lineattrs=GraphData1(color=red pattern=solid ) fillattrs=GraphData1(color=red ); value "2" /markerattrs=GraphData1(color=blue symbol=circlefilled ) lineattrs=GraphData1(color=blue pattern=solid) fillattrs=GraphData1(color=blue ); value "3" /markerattrs=GraphData1(color=green symbol=circlefilled) lineattrs=GraphData1(color=green pattern=solid) fillattrs=GraphData1(color=green ); value "4" /markerattrs=GraphData1(color=Orange symbol=circlefilled) lineattrs=GraphData1(color=Orange pattern=solid) fillattrs=GraphData1(color=Orange ); enddiscreteattrmap; discreteattrvar attrvar=markers1 var=ARMCD attrmap="temp1"; legenditem type=FILL name="S1" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) lineattrs=(color=red) FILLATTRS=(color=red ) label="高剂量组" outlineattrs=(color=white); legenditem type=FILL name="S2" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) lineattrs=(color=blue) FILLATTRS=(color=blue ) label="中剂量组" outlineattrs=(color=white); legenditem type=FILL name="S3" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) lineattrs=(color=green) FILLATTRS=(color=green ) label="低剂量组" outlineattrs=(color=white); legenditem type=FILL name="S4" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) lineattrs=(color=Orange) FILLATTRS=(color=Orange ) label="安慰剂组" outlineattrs=(color=white); layout overlay / wallcolor=white walldisplay=none xaxisopts=( display=( TICKS TICKVALUES line LABEL ) griddisplay=off label="Months since first dose of study drug" linearopts=( minorgrid=off minorticks=off tickvaluepriority=TRUE tickvalueformat=BEST6. tickvaluelist=(0 2 4 6 8 10 12 14 16 18 20 22 24 26) )) yaxisopts=( display=( TICKVALUES) discreteopts=( tickvaluefitpolicy=none)); barchart category=SUBJID response=DY01 / group=markers1 name='L1' datatransparency=0.3 display=(FILL) stat=MEAN barlabel=false orient=horizontal barwidth=0.4 groupdisplay=Stack clusterwidth=0.1; discretelegend 'S1' 'S2' 'S3' 'S4' / autoalign=(topright) opaque=TRUE border=false displayclipped=true across=4 order=columnmajor outerpad=auto TITLEBORDER=FALSE location=inside; endlayout; endgraph; end; run; proc sgrender data=adrs template=setup; run; ; ods rtf close;

代码如上,分别采取PROC SGPLOT与 GTL俩种绘图方式。数据均是模拟随机产生的。关于代码中的语法,此处不做介绍,可私下与小编交流或查看SAS帮助文档。

代码下载链接:

https://www.sas-pharma.com/code/barchart.txt

箱体图

箱式图是临床统计编程中常见图形之一,也是很灵活多变的,譬如:描点、连线等等。

SGPLOT

GTL

代码语言:javascript复制 proc format ; value GROUPfmt 1='高剂量组' 2='中剂量组' 3='低剂量组' 4='安慰剂组'; value vist 1='基线' 2='治疗第2周' 3='治疗第4周' 4='随访期'; run; data adrs; do i=1 to 20; *模拟受试者; SUBJID=put(i,z3.); *模拟组别; ARMCD=mod(i,4)+1; ARM=put(ARMCD,GROUPfmt.); do DY=1 to 4; aval=int(ranuni(1)*20)*int(ranuni(0)*10); output; end; end; run; proc sort data=adrs out=adrs ;by ARMCD ARM DY ; ;quit; /**/ /*proc means data = adrs noprint alpha=0.05;*/ /* by ARMCD ARM DY;*/ /* var aval; */ /* output out=_runtemp_s1 n = n mean = mean q1=q1 q3=q3 std=std median=median nmiss=nmiss min=min max=max lclm=lclm_ uclm=uclm_;*/ /*run;*/ /**/ /*data _runtemp_s1;*/ /* set _runtemp_s1;*/ /* upperstd=mean+std;*/ /* lowerstd=mean-std;*/ /*run;*/ ods rtf file="&runsetup.\箱式图测试结果.rtf" style=threelines_setup startpage=yes; ODS graphics on /width=18cm height=10cm noborder ; ods rtf nogtitle nogfootnote;/*避免title footnote出现在title中*/ title1 j= l "官网:https://www.sas-pharma.com" j= r "作者:Setup"; title2 j= l"微信号:xiaocgn" j= r"日期:&date1."; footnote j= l "箱式图(V1.0)" j= r "欢迎关注公众号"; data Setup; length value FillColor LineColor MARKERCOLOR MARKERSYMBOL LINEPATTERN $30; Id='Setup'; Value="1"; FillColor='Red'; LineColor='Red';LINEPATTERN='solid';LINETHICKNESS=1;MARKERSYMBOL='circlefilled'; MARKERCOLOR='Red'; output; Id='Setup'; Value="2"; FillColor='blue'; LineColor='blue'; LINEPATTERN='solid';LINETHICKNESS=1;MARKERSYMBOL='circlefilled'; MARKERCOLOR='blue'; output; Id='Setup'; Value="3"; FillColor='Green'; LineColor='Green';LINEPATTERN='solid';LINETHICKNESS=1;MARKERSYMBOL='circlefilled'; MARKERCOLOR='Green'; output; Id='Setup'; Value="4"; FillColor='Orange'; LineColor='Orange';LINEPATTERN='solid';LINETHICKNESS=1;MARKERSYMBOL='circlefilled'; MARKERCOLOR='Orange'; output; run; *图中画标题:legenditem; proc sgplot data=adrs dattrmap=Setup; vbox AVAL/ category=DY name='L2' boxwidth=0.4 nofill group=ARMCD ATTRID=Setup /* datalabel=AVAL datalabelattrs=(family="Times New Roman/宋体" size=6) */ connect=mean connectattrs=( Pattern=solid Thickness=1); ; legenditem type=markerline name="S1" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=red symbol=circlefilled) lineattrs=(color=red) label="高剂量组" outlineattrs=(color=white); legenditem type=markerline name="S2" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=blue symbol=circlefilled) lineattrs=(color=blue) label="中剂量组" outlineattrs=(color=white); legenditem type=markerline name="S3" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=green symbol=circlefilled) lineattrs=(color=green) label="低剂量组" outlineattrs=(color=white); legenditem type=markerline name="S4" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=Orange symbol=circlefilled) lineattrs=(color=Orange) label="安慰剂组" outlineattrs=(color=white); /*设置:设置图例*/ keylegend 'S1' 'S2' 'S3' 'S4'/ title="" location= inside position=TOPRIGHT noborder across=1 titleattrs=(color=black family="Times New Roman/宋体" size=10) valueattrs=(color=black family="Times New Roman/宋体" size=10) sortorder=REVERSEAUTO ; legenditem type=TEXT name="S5" /TEXT="Figure xxx.xxx.x.x vbox Plot " TEXTATTRS=(color=black family="Times New Roman/宋体" size=10); keylegend 'S5' / title=" " location= outside position=top noborder down=1 titleattrs=(color=black family="Times New Roman/宋体" size=10) valueattrs=(color=black family="Times New Roman/宋体" size=10) ; ; /*设置:坐标*/ xaxis label="X轴" values=( 1 2 3 4) valuesdisplay=("基线" "治疗第2周" "治疗第4周" "随访期") valueattrs=(color=black family="times new roman/宋体" size=10) labelattrs=(color=black family="Times New Roman/宋体" size=10) fitpolicy=none valuesrotate=diagonal2 ; *刻度值旋转:ROTATE 旋转反向:VALUESROTATE:diagonal | diagonal2 | vertical ; yaxis label="Y轴" values=(-20 to 180 by 20) valueattrs=(color=black family="times new roman/宋体" size=10) labelattrs=(color=black family="Times New Roman/宋体" size=10) fitpolicy=none; run; ods graphics /outputfmt=JPEG; proc template; define statgraph setup; begingraph/ border=false backgroundcolor=white; entryfootnote halign=center "Figure xxx.xxx.x.x boxplot Plot "/ textattrs=(color=black family="times new roman/宋体" size=7); /* entrytitle halign=left "&&ffootnote&ms." / textattrs=(color=black family="times new roman/宋体" size=7);*/ discreteattrmap name="temp1" / ignorecase=true; value "1" /markerattrs=GraphData1(color=red symbol=circlefilled ) lineattrs=GraphData1(color=red pattern=solid ) fillattrs=GraphData1(color=red ); value "2" /markerattrs=GraphData1(color=blue symbol=circlefilled ) lineattrs=GraphData1(color=blue pattern=solid) fillattrs=GraphData1(color=blue ); value "3" /markerattrs=GraphData1(color=green symbol=circlefilled) lineattrs=GraphData1(color=green pattern=solid) fillattrs=GraphData1(color=green ); value "4" /markerattrs=GraphData1(color=Orange symbol=circlefilled) lineattrs=GraphData1(color=Orange pattern=solid) fillattrs=GraphData1(color=Orange ); enddiscreteattrmap; discreteattrvar attrvar=markers1 var=ARMCD attrmap="temp1"; legenditem type=markerline name="S1" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=red symbol=circlefilled) lineattrs=(color=red) label="高剂量组" outlineattrs=(color=white); legenditem type=markerline name="S2" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=blue symbol=circlefilled) lineattrs=(color=blue) label="中剂量组" outlineattrs=(color=white); legenditem type=markerline name="S3" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=green symbol=circlefilled) lineattrs=(color=green) label="低剂量组" outlineattrs=(color=white); legenditem type=markerline name="S4" / LABELATTRS=(color=black family="Times New Roman/宋体" size=6) markerattrs=(color=Orange symbol=circlefilled) lineattrs=(color=Orange) label="安慰剂组" outlineattrs=(color=white); layout overlay //* walldisplay=none*/ cycleattrs=true yaxisopts=(gridDisplay=off LABEL="Y轴" labelattrs=(size=7pt family="Times New Roman/宋体") LABELSPLITCHAR="$" LABELFITPOLICY=SPLITALWAYS tickvalueattrs=( size=7pt family="Times New Roman/宋体") linearopts=(tickvaluelist=(-20 0 20 40 60 80 100 120 140 160 180) tickvaluefitpolicy=none tickvaluepriority=true )) xaxisopts=(display=(ticks tickvalues line label) gridDisplay=off label="X轴" labelattrs=(size=7pt family="Times New Roman/宋体") tickvalueattrs=( size=7pt family="Times New Roman/宋体") linearopts=(tickvaluelist=( 1 2 3 4 ) tickdisplaylist=("基线" "治疗第2周" "治疗第4周" "随访期") tickvaluefitpolicy=none tickvaluepriority=true )) ; boxplot x=DY y=AVAL/ GROUP=markers1 groupdisplay=Cluster connect=mean connectattrs=( Pattern=solid Thickness=1) display=( mean outliers caps connect ) ; discretelegend "S1" "S2" "S3" 'S4'/ border=false location=inside halign=right valign=top across=1 title="" titleattrs=GraphValueText(color=black family="Times New Roman/宋体" size=10pt); endlayout; endgraph; end; run; proc sgrender data=adrs template=setup; run; ; ; ods rtf close;

代码如上,分别采取PROC SGPLOT与 GTL俩种绘图方式。数据均是模拟随机产生的。关于代码中的语法,此处不做介绍,可私下与小编交流或查看SAS帮助文档。

代码下载链接:

https://www.sas-pharma.com/code/boxplot.txt

蜘蛛图

近年来,肿瘤类项目很热门,随之与肿瘤相关的图形也是常常在编程中语句,譬如:蜘蛛图、瀑布图、泳道图与生存图等,首先来看看蜘蛛图的绘制,通常用来描述靶病灶随时间变化而变化的率。

SGPLOT

GTL

代码语言:javascript复制 proc format ; value GROUPfmt 1='高剂量组' 2='中剂量组' 3='低剂量组' 4='安慰剂组'; run; *蜘蛛图 各时点肿瘤大小变化率 衍生DY PCHG; data adrs; do i=1 to 20; *模拟受试者; SUBJID=put(i,z3.); *模拟组别; ARMCD=mod(i,4)+1; ARM=put(ARMCD,GROUPfmt.); *模拟研究时长; do DY=0 to int(ranuni(1)*13); *模拟变化率; pchg=ranuni(int(ranuni(1)*13))*ifn(ranuni(0)


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3