楼主: l1i2n3i4n5g
48358 125

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

71
l1i2n3i4n5g(未真实交易用户) 在职认证  发表于 2018-3-13 14:22:51
Column Lattice with Column Headings
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Column Lattice with Column Headings
  3.             (using template and sgrender procedure)
  4.    Software: SAS 9.4 TS Level 1M2
  5.    Name: justsoso
  6.    Date: 20180305
  7.    From: Getting Started with the Graph Template Language in SAS:
  8.          Examples, Tips, and Techniques for Creating Custom Graphs
  9.    History: 20180305;
  10. %mend;

  11. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  12. /*ods listing gpath='C:\Users\Administrator\Desktop\test20180305' image_dpi=300;*/
  13. ods listing gpath='C:\Users\Administrator\Desktop\test20180305';
  14. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  15. /*ods graphics on / imagename="picture" outputfmt=pdf;*/
  16. /*图片名称picture,输出类型pdf*/
  17. ods graphics off;

  18. /*Column Lattice with Column Headings*/
  19. proc template;
  20. define statgraph Fig_5_4_4;
  21. begingraph;
  22. entrytitle 'Blood Pressure by Cholesterol';
  23. layout lattice / rowdatarange=union order=columnmajor;/*左右单元结构*/
  24.    rowaxes;
  25.       rowaxis / display=(ticks tickvalues) griddisplay=on;
  26.    endrowaxes;
  27.    column2headers;
  28.       entry textattrs=graphlabeltext(weight=bold) 'Systolic';
  29.       entry textattrs=graphlabeltext(weight=bold) 'Diastolic';
  30.    endcolumn2headers;
  31.    layout overlay / xaxisopts=(griddisplay=on);
  32.       scatterplot x=cholesterol y=systolic / datatransparency=0.9
  33.          markerattrs=graphdata1(symbol=circlefilled);
  34.    endlayout;
  35.    layout overlay / xaxisopts=(griddisplay=on);
  36.       scatterplot x=cholesterol y=diastolic / datatransparency=0.9
  37.          markerattrs=graphdata1(symbol=circlefilled);
  38.    endlayout;
  39. endlayout;
  40. endgraph;
  41. end;
  42. run;
  43. proc sgrender template=Fig_5_4_4 data=sashelp.heart;
  44. run;

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


72
l1i2n3i4n5g(未真实交易用户) 在职认证  发表于 2018-3-13 14:30:12
Nested Lattice
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Nested Lattice
  3.             (using template and sgrender procedure)
  4.    Software: SAS 9.4 TS Level 1M2
  5.    Name: justsoso
  6.    Date: 20180305
  7.    From: Getting Started with the Graph Template Language in SAS:
  8.          Examples, Tips, and Techniques for Creating Custom Graphs
  9.    History: 20180305;
  10. %mend;

  11. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  12. /*ods listing gpath='C:\Users\Administrator\Desktop\test20180305' image_dpi=300;*/
  13. ods listing gpath='C:\Users\Administrator\Desktop\test20180305';
  14. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  15. /*ods graphics on / imagename="picture" outputfmt=pdf;*/
  16. /*图片名称picture,输出类型pdf*/
  17. ods graphics off;

  18. /*Nested Lattice*/
  19. proc template; /*--SAS 9.4--*/
  20. define statgraph Fig_5_4_5;
  21. begingraph / subpixel=on;
  22. entrytitle 'Car Statistics';
  23. layout lattice / columns=2;
  24.    layout overlay / yaxisopts=(griddisplay=on)
  25.          xaxisopts=(griddisplay=on);
  26.       scatterplot x=horsepower y=mpg_city / filledoutlinedmarkers=true/*加浓*/
  27.          dataskin=gloss markerattrs=(size=13 symbol=circlefilled)
  28.          markerfillattrs=graphdata1;
  29.       regressionplot x=horsepower y=mpg_city / degree=2;
  30.    endlayout;
  31.    layout lattice / columndatarange=union;
  32.       columnaxes;
  33.          columnaxis;
  34.       endcolumnaxes;
  35.       layout overlay / yaxisopts=(griddisplay=on);
  36.          barchart x=origin y=mpg_city / stat=mean
  37.             dataskin=gloss fillattrs=graphdata3;
  38.       endlayout;
  39.       layout overlay / yaxisopts=(griddisplay=on);
  40.          boxplot x=origin y=mpg_city / fillattrs=graphdata5;
  41.       endlayout;
  42.    endlayout;
  43. endlayout;
  44. endgraph;
  45. end;
  46. run;
  47. proc sgrender template=Fig_5_4_5 data=sashelp.cars; run;

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


73
l1i2n3i4n5g(未真实交易用户) 在职认证  发表于 2018-3-13 14:37:06
Gridded Layout with Embedded Statistics Table
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Gridded Layout with Embedded Statistics Table
  3.             (using template and sgrender procedure)
  4.    Software: SAS 9.4 TS Level 1M2
  5.    Name: justsoso
  6.    Date: 20180305
  7.    From: Getting Started with the Graph Template Language in SAS:
  8.          Examples, Tips, and Techniques for Creating Custom Graphs
  9.    History: 20180305;
  10. %mend;

  11. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  12. /*ods listing gpath='C:\Users\Administrator\Desktop\test20180305' image_dpi=300;*/
  13. ods listing gpath='C:\Users\Administrator\Desktop\test20180305';
  14. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  15. /*ods graphics on / imagename="picture" outputfmt=pdf;*/
  16. /*图片名称picture,输出类型pdf*/
  17. ods graphics off;

  18. /*Gridded Layout with Embedded Statistics Table*/
  19. proc template; /*--SAS 9.4--*/
  20. define statgraph Fig_5_4_6;
  21. begingraph / subpixel=on;
  22. entrytitle 'Car Statistics';
  23. layout overlay / yaxisopts=(griddisplay=on)
  24.       xaxisopts=(griddisplay=on);
  25.    scatterplot x=horsepower y=mpg_city / filledoutlinedmarkers=true
  26.       dataskin=gloss markerattrs=(size=13 symbol=circlefilled)
  27.       markerfillattrs=graphdata1;
  28.    regressionplot x=horsepower y=mpg_city / degree=2;
  29.    layout gridded / rows=3 order=columnmajor border=true
  30.       autoalign=(topright topleft);/*topleft貌似没用*/
  31.       entry textattrs=(size=10) halign=right 'N = ';
  32.       entry textattrs=(size=10) halign=right 'Mean = ';
  33.       entry textattrs=(size=10) halign=right {unicode SIGMA} ' =';
  34.       entry textattrs=(size=10) halign=left
  35.          eval(strip(put(n(mpg_city),4.0)));/*需要进一步研究*/
  36.       entry textattrs=(size=10) halign=left
  37.          eval(strip(put(mean(mpg_city),4.1)));
  38.       entry textattrs=(size=10) halign=left
  39.          eval(strip(put(stddev(mpg_city),4.1)));
  40.    endlayout;
  41. endlayout;
  42. endgraph;
  43. end;
  44. run;
  45. proc sgrender template=Fig_5_4_6 data=sashelp.cars;
  46. run;
  47. ods _all_ close;
  48. /*ods html;      最好将ods destination恢复至默认的html*/
复制代码


74
l1i2n3i4n5g(未真实交易用户) 在职认证  发表于 2018-3-13 16:54:28
Lab Values by Study Week
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Lab Values by Study Week
  3.             (using template and sgrender procedure)
  4.    Software: SAS 9.4 TS Level 1M2
  5.    Name: justsoso
  6.    Date: 20180305
  7.    From: Getting Started with the Graph Template Language in SAS:
  8.          Examples, Tips, and Techniques for Creating Custom Graphs
  9.    History: 20180305;
  10. %mend;

  11. /*--Fig_5_5_1 Lab Values by Study Week--*/
  12. data GTL_GS_Labs_by_Week;
  13. label sgot="SGOT";
  14. label aph="ALKPHOS";
  15. label visit="Study Week";
  16. input visit $ 1-10 treatment $ sgot aph;
  17. datalines;
  18. SCREENING   PLACEBO       .        108.943
  19. WEEK 2      PLACEBO     10.2941     83.740
  20. WEEK 4      PLACEBO     16.1765     76.423
  21. WEEK 6      PLACEBO     17.6471     86.179
  22. WEEK 8      PLACEBO     11.7647     67.480
  23. WEEK 10     PLACEBO     14.7059     68.293
  24. WEEK 12     PLACEBO     13.2353     73.171
  25. WEEK 14     PLACEBO     12.5000     74.797
  26. SCREENING   ACTIVE      12.5000     66.667
  27. WEEK 2      ACTIVE      17.3077     57.961
  28. WEEK 4      ACTIVE      17.9487     68.873
  29. WEEK 6      ACTIVE      26.9231     98.748
  30. WEEK 8      ACTIVE      25.9615     98.211
  31. WEEK 10     ACTIVE      27.2436    100.179
  32. WEEK 12     ACTIVE      29.9679    104.293
  33. WEEK 14     ACTIVE      26.9231    115.921
  34. ;
  35. run;

  36. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  37. /*ods listing gpath='C:\Users\Administrator\Desktop\test20180305' image_dpi=300;*/
  38. ods listing gpath='C:\Users\Administrator\Desktop\test20180305';
  39. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  40. /*ods graphics on / imagename="picture" outputfmt=pdf;*/
  41. /*图片名称picture,输出类型pdf*/
  42. ods graphics off;

  43. /*Lab Values by Study Week*/
  44. proc template;
  45. define statgraph Fig_5_5_1_Lab_Values;
  46. begingraph;
  47. entrytitle "Lab Values by Study Week";
  48. layout gridded / rowgutter=5;
  49.    layout datapanel classvars=(treatment) / columns=1
  50.          rowaxisopts=(griddisplay=on)
  51.          columnaxisopts=(tickvalueattrs=(size=5) griddisplay=on)
  52.          headerLabelDisplay=Value;
  53.       layout prototype / cycleattrs=true;
  54.          seriesPlot X=visit Y=sgot / primary=true display=(markers)
  55.             markerattrs=(size=9px weight=bold)
  56.             lineattrs=(thickness=2px) NAME="series1";
  57.          seriesPlot X=visit Y=aph / yaxis=y2 display=(markers)
  58.             markerattrs=(size=9px weight=bold)
  59.             lineattrs=(thickness=2px) NAME="series2";
  60.       endlayout;
  61.    endlayout;
  62.    DiscreteLegend "series1" "series2" /;
  63. endlayout;
  64. endgraph;
  65. end;
  66. run;
  67. proc sgrender data=GTL_GS_Labs_by_Week template="Fig_5_5_1_Lab_Values";
  68. run;

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


75
l1i2n3i4n5g(未真实交易用户) 在职认证  发表于 2018-3-13 17:02:30
LFT Safety Panel, Baseline versus Study
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: LFT Safety Panel, Baseline versus Study
  3.             (using template and sgrender procedure)
  4.    Software: SAS 9.4 TS Level 1M2
  5.    Name: justsoso
  6.    Date: 20180305
  7.    From: Getting Started with the Graph Template Language in SAS:
  8.          Examples, Tips, and Techniques for Creating Custom Graphs
  9.    History: 20180305;
  10. %mend;

  11. /*--Fig_5_5_2 LFT Lattice--*/
  12. data GTL_GS_LFT_Lattice (keep=drug alat biltot alkph asat
  13.      palat pbiltot palkph pasat visitnum);
  14.   label alat="ALAT (/ULN)";
  15.   label biltot="BILTOT (/ULN)";
  16.   label alkph="ALKPH (/ULN)";
  17.   label asat="ASAT (/ULN)";
  18.   visitnum=1;
  19.   do i= 1 to 100;
  20.     palat = min (4, 2.5 * (abs(rannor(123))) / 3.0);
  21.     pbiltot = min (4, 2.5 * (abs(rannor(123))) / 3.0);
  22.     palkph = min (4, 2.5 * (abs(rannor(123))) / 3.0);
  23.     pasat = min (4, 2.5 * (abs(rannor(123))) / 3.0);
  24.     alat = min (4, 2.5 * (abs(rannor(345))) / 3.0);
  25.     biltot = min (4, 2.5 * (abs(rannor(345))) / 3.0);
  26.     alkph = min (4, 2.5 * (abs(rannor(345))) / 3.0);
  27.     asat = min (4, 2.5 * (abs(rannor(345))) / 3.0);
  28.       j =  rannor(345);
  29.       if j > 0 then drug = "A";
  30.       else drug="B";
  31.       output;
  32.    end;
  33.   visitnum=2;
  34.   do i= 1 to 100;
  35.     palat = min (4, 2.5 * (abs(rannor(789))) / 3.0);
  36.     pbiltot = min (4, 2.5 * (abs(rannor(789))) / 3.0);
  37.     palkph = min (4, 2.5 * (abs(rannor(789))) / 3.0);
  38.     pasat = min (4, 2.5 * (abs(rannor(789))) / 3.0);
  39.     alat = min (4, 2.5 * (abs(rannor(567))) / 3.5);
  40.     biltot = min (4, 2.5 * (abs(rannor(567))) / 3.5);
  41.     alkph = min (4, 2.5 * (abs(rannor(567))) / 3.5);
  42.     asat = min (4, 2.5 * (abs(rannor(567))) / 3.5);
  43.       j =  rannor(567);
  44.       if j > 0 then drug = "A";
  45.       else drug="B";
  46.       output;
  47.    end;
  48.   visitnum=3;
  49.   do i= 1 to 100;
  50.     palat = min (4, 2.5 * (abs(rannor(321))) / 3.0);
  51.     pbiltot = min (4, 2.5 * (abs(rannor(321))) / 3.0);
  52.     palkph = min (4, 2.5 * (abs(rannor(321))) / 3.0);
  53.     pasat = min (4, 2.5 * (abs(rannor(321))) / 3.0);
  54.     alat = min (4, 2.5 * (abs(rannor(975))) / 2.5);
  55.     biltot = min (4, 2.5 * (abs(rannor(975))) / 2.5);
  56.     alkph = min (4, 2.5 * (abs(rannor(975))) / 2.5);
  57.     asat = min (4, 2.5 * (abs(rannor(975))) / 2.5);
  58.       j =  rannor(975);
  59.       if j > 0 then drug = "A";
  60.       else drug="B";
  61.       output;
  62.    end;
  63. run;

  64. proc format;
  65. value wk
  66.   1='1 Week'
  67.   2='3 Months'
  68.   3='6 Months';
  69. value lab
  70.   1='ALAT'
  71.   2='Bilirubin Total'
  72.   3='Alk Phosphatase'
  73.   4='ASAT';
  74. value $trt
  75.   "A"="Drug A (n=240)"
  76.   "B"="Drug B (n=195)";
  77. run;

  78. data GTL_GS_LFT_Lattice2 (keep=visitnum drug labtest result pre);
  79. format visitnum wk. labtest lab. drug $trt.;
  80. label pre='Baseline (/ULN) *' result='Study (/ULN)';
  81. set GTL_GS_LFT_Lattice;
  82.   pre=palat;
  83.   labtest=1;
  84.   result=alat;
  85.   output;
  86.   pre=pbiltot;
  87.   labtest=2;
  88.   result=biltot;
  89.   output;
  90.   pre=palkph;
  91.   labtest=3;
  92.   result=alkph;
  93.   output;
  94.   pre=pasat;
  95.   labtest=4;
  96.   result=asat;
  97.   output;
  98. run;

  99. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  100. /*ods listing gpath='C:\Users\Administrator\Desktop\test20180305' image_dpi=300;*/
  101. ods listing gpath='C:\Users\Administrator\Desktop\test20180305';
  102. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  103. /*ods graphics on / imagename="picture" outputfmt=pdf;*/
  104. /*图片名称picture,输出类型pdf*/
  105. ods graphics off;

  106. /*LFT Safety Panel, Baseline versus Study*/
  107. proc template;
  108. define statgraph Fig_5_5_2_LFT_Lattice;
  109. begingraph;
  110. entrytitle 'LFT Safety Panel, Baseline vs. Study';
  111. layout datalattice rowvar=visitnum columnvar=labtest /
  112.       headerlabeldisplay=value
  113.       rowaxisopts=(linearopts=(viewmin=0 viewmax=4))
  114.       columnaxisopts=(linearopts=(viewmin=0 viewmax=4));
  115.    layout prototype;
  116.       scatterplot x=pre y=result / group=drug;
  117.       referenceline x=1 / lineattrs=(pattern=dash);
  118.       referenceline x=1.5 / lineattrs=(pattern=dash);
  119.       referenceline x=2 / lineattrs=(pattern=dash);
  120.       referenceline y=1 / lineattrs=(pattern=dash);
  121.       referenceline y=1.5 / lineattrs=(pattern=dash);
  122.       referenceline y=2 / lineattrs=(pattern=dash);
  123.    endlayout;
  124. endlayout;
  125. endgraph;
  126. end;
  127. run;
  128. proc sgrender data=GTL_GS_LFT_Lattice2 template=Fig_5_5_2_LFT_Lattice;
  129. run;

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


76
l1i2n3i4n5g(未真实交易用户) 在职认证  发表于 2018-3-13 17:20:19
Most Frequent On-Therapy Adverse Events by Relative Risk
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Most Frequent On-Therapy Adverse Events by Relative Risk
  3.             (using template and sgrender procedure)
  4.    Software: SAS 9.4 TS Level 1M2
  5.    Name: justsoso
  6.    Date: 20180305
  7.    From: Getting Started with the Graph Template Language in SAS:
  8.          Examples, Tips, and Techniques for Creating Custom Graphs
  9.    History: 20180305;
  10. %mend;

  11. /*--Fig_5_5_3 Most Frequend AE--*/
  12. data GTL_GS_AE;
  13.   input ae $1-30 a b low mean high;
  14.   label a='Percent';
  15.   label b='Percent';
  16.   datalines;
  17. ARTHRALGIA                    1   3    1    7     48
  18. NAUSIA                        4   18   2    4     8  
  19. ANOREXIA                      2   3    0.9  3.8   16
  20. HEMATURIA                     2   4    0.8  3.2   15
  21. INSOMNIA                      3   5.5  1.1  3.0   7
  22. VOMITING                      3.5 6    1.2  2.5   6
  23. DYSPEPSIA                     4   10   1.1  2.4   4.5
  24. HEADACHE                      7   10   0.8  1.1   2
  25. BACK PAIN                     5   6    0.8  1.04  2
  26. COUGHING                      8   8    0.5  1.0   2
  27. MYALGEA                       4   4    0.4  1.0   1.9
  28. MELENA                        4.5 4    0.4  0.9   2.2
  29. RHINITIS                      7   6    0.4  0.9   1.9
  30. BRONCHITIS                    5   3.5  0.3  0.7   2
  31. CHEST PAIN                    6   4    0.3  0.8   1.8
  32. DYSPNEA                       7   2.5  0.13 0.3   0.7
  33. ;
  34. run;

  35. proc sort data=GTL_GS_AE out=GTL_GS_AE;
  36.   by mean;
  37.   run;

  38. data GTL_GS_AE_Ref;
  39.   set GTL_GS_AE;
  40.   if mod(_n_, 2) ne 0 then refae=ae;
  41.   run;

  42. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  43. /*ods listing gpath='C:\Users\Administrator\Desktop\test20180305' image_dpi=300;*/
  44. ods listing gpath='C:\Users\Administrator\Desktop\test20180305';
  45. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  46. /*ods graphics on / imagename="picture" outputfmt=pdf;*/
  47. /*图片名称picture,输出类型pdf*/
  48. ods graphics off;

  49. /*Most Frequent On-Therapy Adverse Events by Relative Risk*/
  50. proc template;
  51. define statgraph Fig_5_5_1_MostFreqAE;
  52. begingraph / designwidth=8in designheight=4in;
  53. entrytitle "Most Frequent On-Therapy AE Sorted by Relative Risk";
  54. layout lattice / columns=2 rowdatarange=union;
  55.    rowaxes;
  56.       rowaxis / display=(ticks tickvalues line)
  57.          tickvalueattrs=(size=7);
  58.    endrowaxes;
  59.    layout overlay / xaxisopts=(displaysecondary=(ticks)
  60.          tickvalueattrs=(size=7) linearopts=(thresholdmax=1));
  61.       referenceline y=refae / lineattrs=(thickness=14)
  62.          datatransparency=0.8;
  63.       scatterplot x=a y=ae / name='a' legendlabel='Drug A (N=216)'
  64.          markerattrs=graphdata1(symbol=circlefilled size=10);
  65.       scatterplot x=b y=ae / name='b' legendlabel='Drug B (N=431)'
  66.          markerattrs=graphdata2(symbol=trianglefilled size=10);
  67.       discretelegend 'a' 'b' / border=false valueattrs=(size=5);
  68.    endlayout;
  69.    layout overlay / xaxisopts=(label='Relative Risk with 95% CL'
  70.          displaysecondary=(ticks) tickvalueattrs=(size=7)
  71.          type=log logopts=(base=2 viewmin=0.125 viewmax=64
  72.          tickintervalstyle=logexpand));
  73.       referenceline y=refae / lineattrs=(thickness=16)
  74.          datatransparency=0.8;
  75.       scatterplot x=mean y=ae / xerrorlower=low xerrorupper=high
  76.          markerattrs=(symbol=circlefilled size=10);
  77.       referenceline x=1 /
  78.          lineattrs=graphdatadefault(pattern=shortdash);
  79.    endlayout;
  80. endlayout;
  81. endgraph;
  82. end; run;
  83. proc sgrender data=GTL_GS_AE_Ref(obs=10) template=Fig_5_5_1_MostFreqAE;
  84. run;

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


77
l1i2n3i4n5g(未真实交易用户) 在职认证  发表于 2018-3-14 09:29:36
Common Axis Features
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Common Axis Features
  3.             (using template and sgrender procedure)
  4.    Software: SAS 9.4 TS Level 1M2
  5.    Name: justsoso
  6.    Date: 20180305
  7.    From: Getting Started with the Graph Template Language in SAS:
  8.          Examples, Tips, and Techniques for Creating Custom Graphs
  9.    History: 20180305;
  10. %mend;

  11. /*--Fig_6_2_1 Common Axis Opts--*/
  12. proc means data=sashelp.cars noprint;
  13.   class type;
  14.   var mpg_city;
  15.   output out=CarsMeanMileage
  16.          n=N
  17.          mean=Mean
  18.          median=Median;
  19. run;

  20. data GTL_GS_Cars;
  21.   format mean median 4.1;
  22.   set sashelp.cars CarsMeanMileage(where=(_type_ eq 1)
  23.                                    rename=(type=TypeMean));
  24.   if(typemean ne 'Hybrid');
  25.   if(type ne 'Hybrid');
  26.   NLabel='N'; meanLabel='Mean'; medianLabel='Median';
  27.   run;
  28. /*proc print data=GTL_GS_Cars;run;*/

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

  36. /*Common Axis Features*/
  37. proc template; /*--SAS 9.4--*/
  38. define statgraph Fig_6_2_1;
  39. begingraph / subpixel=on;
  40. entrytitle 'Mileage by Type';
  41. layout overlay / xaxisopts=(display=(ticks tickvalues))
  42.       yaxisopts=(label='Mean Mileage' griddisplay=on
  43.       offsetmin=0.25 labelposition=datacenter)
  44.       y2axisopts=(offsetmin=0.05 offsetmax=0.8
  45.       display=(ticks tickvalues));
  46.    barchart x=type y=mpg_city / stat=mean dataskin=sheen;
  47.    scatterplot x=typemean y=NLabel / markercharacter=n
  48.       labelstrip=true yaxis=y2;
  49.    scatterplot x=typemean y=meanLabel / markercharacter=mean
  50.       labelstrip=true yaxis=y2;
  51.    scatterplot x=typemean y=medianLabel / markercharacter=median
  52.       labelstrip=true yaxis=y2;
  53. endlayout;
  54. endgraph;
  55. end;
  56. run;
  57. ods listing style=analysis;
  58. proc sgrender template=Fig_6_2_1 data=GTL_GS_Cars;
  59. run;

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


78
l1i2n3i4n5g(未真实交易用户) 在职认证  发表于 2018-3-14 09:36:06
Linear Axis Features
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Linear Axis Features
  3.             (using template and sgrender procedure)
  4.    Software: SAS 9.4 TS Level 1M2
  5.    Name: justsoso
  6.    Date: 20180305
  7.    From: Getting Started with the Graph Template Language in SAS:
  8.          Examples, Tips, and Techniques for Creating Custom Graphs
  9.    History: 20180305;
  10. %mend;

  11. /*--Fig_6_2_1 Common Axis Opts--*/
  12. proc means data=sashelp.cars noprint;
  13.   class type;
  14.   var mpg_city;
  15.   output out=CarsMeanMileage
  16.          n=N
  17.          mean=Mean
  18.          median=Median;
  19. run;

  20. data GTL_GS_Cars;
  21.   format mean median 4.1;
  22.   set sashelp.cars CarsMeanMileage(where=(_type_ eq 1)
  23.                                    rename=(type=TypeMean));
  24.   if(typemean ne 'Hybrid');
  25.   if(type ne 'Hybrid');
  26.   NLabel='N'; meanLabel='Mean'; medianLabel='Median';
  27.   run;
  28. /*proc print data=GTL_GS_Cars;run;*/

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

  36. /*Linear Axis Features*/
  37. proc template;
  38. define statgraph Fig_6_2_2;
  39. begingraph;
  40. entrytitle 'Mileage by Horsepower';
  41. layout overlay / xaxisopts=(griddisplay=on
  42.       linearopts=(tickvaluelist=(150 200 250 300 350)))
  43.       yaxisopts=(griddisplay=on
  44.       linearopts=(tickvaluepriority=true/*指定的tickvalue优先*/
  45.       tickvaluesequence=(start=0 end=50 increment=10)));
  46.    scatterplot x=horsepower y=mpg_city;
  47. endlayout;
  48. endgraph;
  49. end;
  50. run;
  51. ods listing style=htmlblue;
  52. proc sgrender template=Fig_6_2_2 data=GTL_GS_Cars;
  53. run;

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


79
l1i2n3i4n5g(未真实交易用户) 在职认证  发表于 2018-3-14 09:45:21
Discrete Axis Features
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Discrete Axis Features
  3.             (using template and sgrender procedure)
  4.    Software: SAS 9.4 TS Level 1M2
  5.    Name: justsoso
  6.    Date: 20180305
  7.    From: Getting Started with the Graph Template Language in SAS:
  8.          Examples, Tips, and Techniques for Creating Custom Graphs
  9.    History: 20180305;
  10. %mend;

  11. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  12. /*ods listing gpath='C:\Users\Administrator\Desktop\test20180305' image_dpi=300;*/
  13. ods listing gpath='C:\Users\Administrator\Desktop\test20180305';
  14. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  15. /*ods graphics on / imagename="picture" outputfmt=pdf;*/
  16. /*图片名称picture,输出类型pdf*/
  17. ods graphics off;

  18. /*Discrete Axis Features*/
  19. proc template; /*--SAS 9.4--*/
  20. define statgraph Fig_6_2_3;
  21. begingraph / subpixel=on;
  22. entrytitle 'Mean Mileage by Make';
  23. layout overlay / xaxisopts=(display=(tickvalues)
  24.       discreteopts=(tickvaluefitpolicy=split
  25.       tickvaluelist=('Acura' 'Audi' 'BMW' 'Lexus' 'Mercedes-Benz' 'Porsche')
  26.       tickdisplaylist=('Acura' 'Audi' 'BMW' 'Lexus' 'Mercedes Benz' 'Porsche')));
  27.    barchart x=make y=mpg_city / stat=mean dataskin=crisp
  28.       barlabel=true;
  29. endlayout;
  30. endgraph;
  31. end;
  32. run;
  33. ods listing style=htmlblue;
  34. proc sgrender template=Fig_6_2_3
  35. data=sashelp.cars(where=(msrp > 60000));
  36. run;

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


80
l1i2n3i4n5g(未真实交易用户) 在职认证  发表于 2018-3-14 09:51:04
Log Axis Features
  1. %macro comment();    /*这是一种比较特殊的注释方式*/
  2.    Picture: Log Axis Features
  3.             (using template and sgrender procedure)
  4.    Software: SAS 9.4 TS Level 1M2
  5.    Name: justsoso
  6.    Date: 20180305
  7.    From: Getting Started with the Graph Template Language in SAS:
  8.          Examples, Tips, and Techniques for Creating Custom Graphs
  9.    History: 20180305;
  10. %mend;

  11. ods _all_ close;     /*关闭所有ods destinations,避免不必要的输出,节省计算机资源*/
  12. /*ods listing gpath='C:\Users\Administrator\Desktop\test20180305' image_dpi=300;*/
  13. ods listing gpath='C:\Users\Administrator\Desktop\test20180305';
  14. /*打开ods listing这一destination,指定图片保存路径,★★★★★需提前建立*/
  15. /*ods graphics on / imagename="picture" outputfmt=pdf;*/
  16. /*图片名称picture,输出类型pdf*/
  17. ods graphics off;

  18. /*Log Axis Features*/
  19. proc template;
  20. define statgraph Fig_6_2_4;
  21. begingraph;
  22. entrytitle 'MSRP by Horsepower';
  23. layout overlay / xaxisopts=(type=log griddisplay=on
  24.       logopts=(base=2 tickintervalstyle=linear))
  25.       yaxisopts=(griddisplay=on
  26.       linearopts=(tickvaluepriority=true
  27.       tickvaluelist=(10000 50000 100000 200000)));
  28.    scatterplot x=horsepower y=msrp;
  29. endlayout;
  30. endgraph;
  31. end;
  32. run;
  33. ods listing style=htmlblue;
  34. proc sgrender template=Fig_6_2_4 data=sashelp.cars;
  35. run;

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


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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-6 05:55