楼主: l1i2n3i4n5g
31797 123

[学习分享] 如何用SAS画统计图,这是我的学习分享!   [推广有奖]

教授

25%

还不是VIP/贵宾

-

威望
0
论坛币
4501 个
通用积分
76.6084
学术水平
171 点
热心指数
204 点
信用等级
133 点
经验
24581 点
帖子
584
精华
1
在线时间
1862 小时
注册时间
2008-5-25
最后登录
2023-9-20

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

准备花时间深入学习SAS的画图功能,主要方式是看到好的统计图反过来研究具体的SAS程序,我会不定期更新学习笔记。


另外找了一些资料,供大家参考学习。
http://robslink.com/SAS/Home.htm
https://blogs.sas.com/content/topic/data-visualization/

Picture: Dose Response Plot (Clinical Trial Reporting)
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Dose Response Plot (Clinical Trial Reporting)
  3.    Software: SAS 9.4 TS Level 1M2
  4.    Name: justsoso
  5.    Date: 20171129
  6.    From: Clinical Trial Reporting Using SAS/GRAPH® SG Procedures
  7.          http://support.sas.com/resources/papers/proceedings09/174-2009.pdf
  8.    History: 20171129;
  9. %mend;

  10. /*建立数据集response,用于后续画图*/
  11. data response;
  12. label response = 'Mean Clinical Response'    /*label会体现在图的x、y轴label*/
  13.       visit    = 'Visit';
  14. input response    /*临床上关注的某个定量指标*/
  15.       visit       /*访视次数,第0天、第1天……*/
  16.       trt @@;     /*处理因素(药物种类)*/
  17. cards;
  18. 9.4 0 1 9.35 1 1 8.1 2 1 6.3 3 1 4 4 1 2.2 5 1 1.6 6 1 1.3 7 1 0.7 8 1
  19. 0.8 9 1 0.65 10 1 9.35 0 2 9.37 1 2 8.7 2 2 8.2 3 2 7.8 4 2 4.4 5 2
  20. 2 6 2 1.9 7 2 1.5 8 2 1.4 9 2 1.2 10 2
  21. ;
  22. run;

  23. /*自定义格式,用于刻度值的自定义显示*/
  24. proc format;
  25.    value visitfmt
  26.       0 = "Baseline"   1 = "Day 1"   2 = "Day 2"    3 = "Day 3"
  27.       4 = "Day 4"      5 = "Day 5"   6 = "Day 6"    7 = "Day 7"
  28.       8 = "Day 8"      9 = "Day 9"   10 = "Day 10";
  29.    value trtfmt
  30.       1 = "Super Drug" 2 = "Old Drug";
  31. run;

  32. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  33. ods listing gpath='C:\Users\Administrator\Desktop\test20171129';
  34. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  35. ods graphics on / imagename="picture" outputfmt=pdf;     /*图片名称picture,输出类型pdf*/
  36. proc sgplot data=response;
  37.    format visit visitfmt. trt trtfmt.;    /*这里用到前面的自定义格式*/
  38.    series x=visit y=response / group=trt markers;
  39.    /*指定x、y轴变量,group指定分组变量,节点处画markers*/
  40.    refline 1 / axis=x;     /*x=1处画参考线*/
  41.    keylegend / position=topright across=1 location=inside;
  42.    /*画图例,位置右上,一列,在frame里面*/
  43.    xaxis grid;    /*画x轴网格线*/
  44.    yaxis grid;    /*画y轴网格线*/
  45. run;
  46. ods _all_ close;
  47. ods html;      /*最好将ods destination恢复至默认的html*/
复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:如何用 统计图 destination Proceedings Procedures

Clinical_Graphs_Using_SAS(Mar 21, 2016 by Sanjay Matange).pdf

9.2 MB

需要: 10 个论坛币  [购买]

已有 7 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
dxystata + 100 + 1 精彩帖子
wwqqer + 100 精彩帖子
kychan + 100 精彩帖子
whymath + 5 + 1 + 1 + 1 精彩帖子
第二次爱上你4 + 1 + 1 + 1 精彩帖子
eijuhz + 1 鼓励积极发帖讨论
孤单的我们 + 5 + 1 + 1 + 1 精彩帖子

总评分: 经验 + 300  论坛币 + 10  学术水平 + 3  热心指数 + 5  信用等级 + 3   查看全部评分

本帖被以下文库推荐

沙发
l1i2n3i4n5g 在职认证  发表于 2017-12-1 09:19:31 |只看作者 |坛友微信交流群
Picture: Cancer Mortality Plot (Clinical Trial Reporting)
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Cancer Mortality Plot (Clinical Trial Reporting)
  3.    Software: SAS 9.4 TS Level 1M2
  4.    Name: justsoso
  5.    Date: 20171130
  6.    From: Clinical Trial Reporting Using SAS/GRAPH? SG Procedures
  7.          http://support.sas.com/resources/papers/proceedings09/174-2009.pdf
  8.    History: 20171130;
  9. %mend;

  10. /*建立数据集cancer,用于后续画图*/
  11. data cancer;
  12. input cause : &$20.  /*死亡原因,各种癌症等*/
  13.       deaths;        /*各种原因的死亡数*/
  14. cards4;
  15. Lung Cancer  160000
  16. Colorectal Cancer  50000
  17. Breast Cancer  45000
  18. Pancreatic Cancer  40000
  19. Prostate Cancer  35000
  20. Leukemia  30000
  21. Lymphoma  28000
  22. Liver Cancer  26000
  23. Ovarian Cancer  24000
  24. Esophageal Cancer  22000
  25. Bladder Cancer  20000
  26. Kidney Cancer  18000
  27. ;;;;     /*注意“cause : &$20.”“cards4”“;;;;”用法!*/
  28. run;

  29. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  30. ods listing gpath='C:\Users\Administrator\Desktop\test20171130';
  31. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  32. ods graphics on / imagename="picture" outputfmt=pdf;     /*图片名称picture,输出类型pdf*/
  33. /*按变量deaths降序*/
  34. proc sort data=cancer;
  35.    by descending deaths;
  36. run;
  37. proc sgplot data=cancer;
  38.    dot cause / response=deaths;     /*y轴cause,x轴deaths*/
  39.    yaxis discreteorder=data display=(nolabel);     /*y轴顺序按照排序后的data?没有label*/
  40.    xaxis label='Number of Deaths';     /*指定x轴label*/
  41. run;
  42. ods _all_ close;
  43. ods html;      /*最好将ods destination恢复至默认的html*/
复制代码


已有 1 人评分论坛币 学术水平 收起 理由
albusdzx + 5 + 1 老哥,稳

总评分: 论坛币 + 5  学术水平 + 1   查看全部评分

使用道具

藤椅
l1i2n3i4n5g 在职认证  发表于 2017-12-1 10:15:09 |只看作者 |坛友微信交流群
Picture: Plasma Concentration Profile (Clinical Trial Reporting)
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Plasma Concentration Profile (Clinical Trial Reporting)
  3.    Software: SAS 9.4 TS Level 1M2
  4.    Name: justsoso
  5.    Date: 20171201
  6.    From: Clinical Trial Reporting Using SAS/GRAPH? SG Procedures
  7.          http://support.sas.com/resources/papers/proceedings09/174-2009.pdf
  8.    History: 20171201;
  9. %mend;

  10. /*建立数据集pk,用于后续画图*/
  11. data pk;
  12. input time conc vx vy vlabel :$20.
  13. vx2 vy2 vlabel2 :$20.
  14. vx3 vy3 vlabel3 :$20.;
  15. cards;
  16. 0.25 0.00 3.5 3 AUC=12.03 5 6.76 Cmax=6.76 0.75 8 Tmax=0.75
  17. 0.25 1.00 . . . . . . . . .
  18. 0.50 3.50 . . . . . . . . .
  19. 0.75 6.7 . . . . . . . . .
  20. 1 5.5 . . . . . . . . .
  21. 1.5 4.5 . . . . . . . . .
  22. 1.75 3.8 . . . . . . . . .
  23. 2 3 . . . . . . . . .
  24. 2.5 2.5 . . . . . . . . .
  25. 3 2 . . . . . . . . .
  26. 4 1 . . . . . . . . .
  27. 6 0.6 . . . . . . . . .
  28. 8 0.1 . . . . . . . . .
  29. ;
  30. run;

  31. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  32. ods listing gpath='C:\Users\Administrator\Desktop\test20171201';
  33. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  34. ods graphics on / imagename="picture" outputfmt=pdf noborder;
  35. /*图片名称picture,输出类型pdf,图片不需要边框*/
  36. proc sgplot data=pk noautolegend;   /*不需要图例*/
  37.    band x=time lower=0 upper=conc;  /*色带,沿着x轴刷,从y=0向上到y=conc*/
  38.    series x=time y=conc / markers   /*指定time为x轴变量,conc为y轴变量*/
  39.       markerattrs=graphdata1 (symbol=circlefilled);  /*用markers画出小圆点*/
  40.    xaxis offsetmin=0  /*x轴上最小值与y轴的距离比例*/
  41.       label='Time relative to dose (hours)';
  42.    yaxis max=8.0 offsetmin=0  /*y轴最大值为8*/
  43.       label='Plasma concentration [ng/mL]';
  44.    vector x=vx y=vy / xorigin=2 yorigin=1.5  /*画箭头,起点是(vx,vy),终点(2,1.5)*/
  45.       lineattrs=(color=black)
  46.       datalabel=vlabel arrowshape=filled;  /*箭头注释,箭头形状*/
  47.    vector x=vx2 y=vy2 / xorigin=0  /*画参考线,起点是(vx2,vy2),终点(0,6.76)*/
  48.       yorigin=6.76 lineattrs=
  49.       (pattern=mediumdash color=black)  /*线条属性*/
  50.       datalabel=vlabel2 noarrowheads;
  51.    vector x=vx3 y=vy3 / xorigin=.75
  52.       yorigin=0 lineattrs=
  53.       (pattern=shortdash color=black) datalabel=vlabel3 noarrowheads;
  54. run;
  55. ods _all_ close;
  56. ods html;      /*最好将ods destination恢复至默认的html*/
复制代码


已有 1 人评分经验 收起 理由
np84 + 100 精彩帖子

总评分: 经验 + 100   查看全部评分

使用道具

板凳
l1i2n3i4n5g 在职认证  发表于 2017-12-1 12:44:19 |只看作者 |坛友微信交流群
Picture: Plasma Concentration Profile (Clinical Trial Reporting)
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Mean Percent Change from Baseline (Clinical Trial Reporting)
  3.    Software: SAS 9.4 TS Level 1M2
  4.    Name: justsoso
  5.    Date: 20171202
  6.    From: Clinical Trial Reporting Using SAS/GRAPH? SG Procedures
  7.          http://support.sas.com/resources/papers/proceedings09/174-2009.pdf
  8.    History: 20171202;
  9. %mend;

  10. /*建立数据集response,用于后续画图*/
  11. data response;
  12. infile cards truncover;
  13. input trt week perc lo hi end;
  14. cards;
  15. 1 0 0
  16. 1 3 8 7.5 8.5
  17. 1 6 7 6.5 7.5
  18. 1 9 8 7.5 8.5
  19. 1 12 9 8.5 9.5 9
  20. 1 15 6 5.5 6.5 4.5
  21. 2 0 0
  22. 2 3 2 1.5 2.5
  23. 2 6 -1 -1.5 -0.5
  24. 2 9 2 1.5 2.5
  25. 2 12 3 2.5 3.5 3
  26. 2 15 4 3.5 4.5 4.5
  27. ;
  28. run;

  29. /*自定义格式,用于图例的自定义显示*/
  30. proc format;
  31.    value trtfmt
  32.       1 = "Placebo"   2 = "Treetment 10mg";
  33. run;

  34. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  35. ods listing gpath='C:\Users\Administrator\Desktop\test20171202';
  36. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  37. ods graphics on / imagename="picture" outputfmt=pdf noborder;
  38. /*图片名称picture,输出类型pdf,图片不需要边框*/
  39. proc sgplot data=response;
  40.    format trt trtfmt.;  /*使用自定义格式*/
  41.    band y=week lower=12.1 upper=15 /  /*画色带,x=12.1到x=15*/
  42.    transparency=0.8 fillattrs=graphdata1;  /*透明度0.8,指定填充属性*/
  43.    scatter x=week y=perc / group=trt   /*画散点图,下T为lo,上T为hi*/
  44.       yerrorlower=lo yerrorupper=hi
  45.       markerattrs=(symbol=circlefilled)
  46.    name="scat";   /*这里是指定图例?*/
  47.    series x=week y=perc / group=trt  /*连线*/
  48.       lineattrs=(pattern=solid);
  49.    series x=week y=end / group=trt  /*连线*/
  50.       lineattrs=(pattern=shortdash)
  51.       markers markerattrs=(symbol=circle);   /**/
  52.    xaxis integer values=(0 to 15 by 3) /*设置x轴*/
  53.       label="Weeks in Treatment";
  54.    yaxis max=10 label="Percent Change";   /*设置y轴*/
  55.    refline 0;
  56.    refline 13.5 / axis=x
  57.       label="|-- Washout --|"
  58.       labelloc=outside labelpos=min    /*纵向min*/
  59.       lineattrs=(thickness=0px);    /*不要显示这条线*/
  60.    keylegend "scat" / title="" noborder;  /*设置图例*/
  61. run;
  62. ods _all_ close;
  63. /*ods html;      最好将ods destination恢复至默认的html*/
复制代码


使用道具

报纸
l1i2n3i4n5g 在职认证  发表于 2018-1-23 13:47:20 |只看作者 |坛友微信交流群
Picture: Clinical Study Design Plot (Clinical Trial Reporting)
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Clinical Study Design Plot (Clinical Trial Reporting)
  3.    Software: SAS 9.4 TS Level 1M2
  4.    Name: justsoso
  5.    Date: 20180123
  6.    From: Clinical Trial Reporting Using SAS/GRAPH? SG Procedures
  7.          http://support.sas.com/resources/papers/proceedings09/174-2009.pdf
  8.    History: 20180123;
  9. %mend;

  10. /*建立数据集response,用于后续画图*/
  11. data txsize;
  12. input (c500 t500 c100 t100 c50 t50 c25 t25) (: percent3.);/*此方式有一定简化作用*/
  13. cards;
  14. 10% 5% 12% 10% 18% 18% . .
  15. 20% 7% 20% 12% 20% 19% . .
  16. 30% 9% 30% 17% 30% 22% 30% 29%
  17. 40% 10% 40% 18% 40% 27% 40% 35%
  18. 50% 10% 50% 20% 50% 29% 50% 39%
  19. 60% 9% 60% 20% 60% 30% 60% 41%
  20. 70% 9% 70% 20% 70% 29% 70% 41%
  21. 80% 8% 80% 19% 80% 28% 80% 40%
  22. 90% 7% 90% 18% 90% 27% 90% 39%
  23. 95% 6% 95% 17% 95% 26% 95% 38%
  24. ;
  25. run;

  26. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  27. ods listing gpath='C:\Users\Administrator\Desktop\test20180123';
  28. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  29. ods graphics on / imagename="picture" outputfmt=pdf noborder;
  30. /*图片名称picture,输出类型pdf,图片不需要边框*/
  31. ods escapechar='~';  /*The ODS escape character is set to ~*/
  32. proc sgplot data=txsize noautolegend;    /*不要自动画图例*/
  33.    reg x=c500 y=t500 / curvelabel="n=500"  /*回归线标注"n=500"*/
  34.       curvelabelpos=max  /*max表示回归线最右边*/
  35.       degree=2    /*degree取值1-10越小越光滑*/
  36.       nomarkers   /*原始点的位置不要画出来*/
  37.       lineattrs=(thickness=2px  /*回归线粗细,2个像素*/
  38.       pattern=solid);  /*实线*/

  39.    reg x=c100 y=t100 / curvelabel="n=100"
  40.       curvelabelpos=max degree=2 nomarkers
  41.       lineattrs=(thickness=2px
  42.       pattern=solid);

  43.    reg x=c50 y=t50 / curvelabel="n=50"
  44.       curvelabelpos=max degree=2 nomarkers
  45.       lineattrs=(thickness=2px
  46.       pattern=solid);

  47.    reg x=c25 y=t25 / curvelabel="n=25"
  48.       curvelabelpos=max degree=2 nomarkers
  49.       lineattrs=(thickness=2px
  50.       pattern=solid);

  51.    refline 0.5 /axis=x transparency=0.5;  /*参考线x=0.5,透明度0.5*/
  52.    xaxis label='Response rate in the control group' /*x轴label*/
  53.       values=(0.0 to 1.0 by 0.1) grid; /*x轴刻度*/
  54.    yaxis label='Anticipated smallest
  55.       treatment effect (~{unicode delta_u} vs control)'
  56.       /*注意~{unicode delta_u}*/
  57.        min=0.0 max=0.5 grid;  
  58.    inset ("~{unicode alpha} ="="5%"
  59.       "~{unicode beta} ="="20%") /
  60.       position=topright noborder
  61.       textattrs=graphtitletext;
  62. run;
  63. ods _all_ close;
  64. /*ods html;      最好将ods destination恢复至默认的html*/
复制代码


使用道具

地板
l1i2n3i4n5g 在职认证  发表于 2018-1-24 10:18:29 |只看作者 |坛友微信交流群
Picture: Demographic Profile in a LATTICE Layout (Clinical Trial Reporting)
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Demographic Profile in a LATTICE Layout (Clinical Trial Reporting)
  3.    Software: SAS 9.4 TS Level 1M2
  4.    Name: justsoso
  5.    Date: 20180124
  6.    From: Clinical Trial Reporting Using SAS/GRAPH? SG Procedures
  7.          http://support.sas.com/resources/papers/proceedings09/174-2009.pdf
  8.    History: 20180124;
  9. %mend;

  10. /*建立数据集demog,用于后续画图*/
  11. data demog;
  12.    infile cards missover;  /*这句不可少*/
  13.    input (gender race trt) (:$20.) age @;  /*这种用法很巧妙!★★★★★*/
  14.    do while(not missing(age));
  15.       output;
  16.       input age @;
  17.    end;
  18. cards;
  19. male white control 10 20 20 20 30 25 10 4 6 2
  20. male white experimental 12 5 2 54 3 43 12
  21. male black control 12 3 5 10 5 32 4 3 30 3 20
  22. male black experimental 5 45 6 13 22 54 12
  23. female white control 12 45 45 1 2 3 54 2 1 2 35
  24. female white experimental 5 23 5 2
  25. female black control 12 50 25 84 30 15 8 15
  26. female black experimental 2 35 4 3 45 40
  27. ;
  28. run;

  29. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  30. ods listing gpath='C:\Users\Administrator\Desktop\test20180124';
  31. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  32. /*ods graphics on / imagename="picture" outputfmt=pdf noborder;*/
  33. ods graphics off / imagename="picture" outputfmt=pdf noborder;
  34. /*图片名称picture,输出类型pdf,图片不需要边框*/

  35. proc sgpanel data=demog;
  36.    panelby gender race / layout=lattice;
  37.    hbox age / category=trt datalabel;  /*datalabel,异常点标注*/
  38.    rowaxis display=(nolabel);  /*行坐标不标注*/
  39.    /*colaxis display=(nolabel); */
  40. run;

  41. ods _all_ close;
  42. /*ods html;      最好将ods destination恢复至默认的html*/
复制代码
Demographic Profile in a PANEL Layout
  1. /*Demographic Profile in a PANEL Layout*/
  2. proc sgpanel data=demog;
  3.    panelby gender race / layout=panel columns=4;
  4.    hbox age / category=trt;
  5.    rowaxis display=(nolabel);
  6. run;
复制代码



使用道具

7
l1i2n3i4n5g 在职认证  发表于 2018-1-24 15:00:49 |只看作者 |坛友微信交流群
SGPanel21.png
  1. /*建立数据集demog,用于后续画图*/
  2. data hyp;
  3. label rawp='rawp p-value' adjp='weight adjusted p-value';
  4. do trt='TreatmentA', 'TreatmentB';
  5.    do hyp='H11', 'H12', 'H21', 'H22';
  6.       input rawp adjp;
  7.       output;
  8.    end;
  9. end;
  10. cards;
  11. 0.025 0.028
  12. 0.004 0.022
  13. 0.01 0.029
  14. 0.006 0.029
  15. 0.025 0.028
  16. 0.007 0.06
  17. 0.01 0.025
  18. 0.006 0.025
  19. ;
  20. run;

  21. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  22. ods listing gpath='C:\Users\Administrator\Desktop\test20180124';
  23. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  24. /*ods graphics on / imagename="picture" outputfmt=pdf noborder;*/
  25. ods graphics off;
  26. /*图片名称picture,输出类型pdf,图片不需要边框*/

  27. /*Comparison of p-values in a COLUMNLATTICE Layout*/
  28. proc sgpanel data=hyp;
  29.    panelby trt / novarname
  30.       layout=columnlattice;
  31.    series x=hyp y=rawp / markers
  32.       markerattrs=(size=6pt);
  33.    series x=hyp y=adjp / markers
  34.       markerattrs=(size=6pt symbol=square);
  35.    rowaxis label='P-value';
  36.    colaxis label='Hypothesis';
  37.    refline 0.05 /
  38.    lineattrs=(pattern=shortdash);
  39. run;

  40. ods _all_ close;
  41. /*ods html;      最好将ods destination恢复至默认的html*/
复制代码


已有 1 人评分经验 收起 理由
np84 + 100 精彩帖子

总评分: 经验 + 100   查看全部评分

使用道具

8
384390412 发表于 2018-1-24 15:24:40 |只看作者 |坛友微信交流群
好贴,必须要顶,楼主的经验总结很宝贵。

使用道具

9
384390412 发表于 2018-1-24 15:53:51 |只看作者 |坛友微信交流群
建议补充不同图形的适用范围,比如时间反应关系,时间剂量效应……

使用道具

10
l1i2n3i4n5g 在职认证  发表于 2018-1-29 13:53:44 |只看作者 |坛友微信交流群
384390412 发表于 2018-1-24 15:53
建议补充不同图形的适用范围,比如时间反应关系,时间剂量效应……
好建议 ,适当时候统一补充

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-26 01:38