Posted By

webonomic on 06/11/08


Tagged

needle graph SGPLOT plot


Versions (?)

Needle Plot with SGPLOT


 / Published in: SAS
 

URL: http://jaredprins.squarespace.com/blog/2008/6/11/needle-plot-with-sgplot.html

  1. /* This sample creates a needle plot with overlaid lines. */
  2.  
  3. /* Define a format to order the horizontal axis and
  4.   the format for the values on the vertical axis. */
  5. proc format;
  6. value matfmt
  7. 1='1 mo'
  8. 2='3 mo'
  9. 3='6 mo'
  10. 6='1 yr'
  11. 7='2 yr'
  12. 8='3 yr'
  13. 9='5 yr'
  14. 11='10 yr '
  15. 14='30 yr';
  16. picture yldfmt
  17. low-high='9%';
  18. run;
  19.  
  20. /* Create sample data. */
  21. data yield;
  22. input matcur yldcur mat1mo yld1mo mat1yr yld1yr;
  23. label yldcur='January 2008' yld1mo = 'December 2007' yld1yr = 'January 2007';
  24. format mat1yr matfmt. mat1mo matfmt. matcur matfmt.
  25. yldcur yldfmt. yld1mo yldfmt. yld1yr yldfmt.;
  26. datalines;
  27. 1 2.63 1 2.76 1 4.97
  28. 2 2.86 2 3.04 2 5.12
  29. 3 2.86 3 3.37 3 5.16
  30. 6 2.69 6 3.31 6 5.07
  31. 7 2.36 7 3.19 7 4.89
  32. 8 2.39 8 3.2 8 4.8
  33. 9 2.86 9 3.53 9 4.75
  34. 11 4.3 11 4.6 11 4.94
  35. 14 4.28 14 4.55 14 4.85
  36. ;
  37. run;
  38.  
  39. title 'Government Bond Yield Curve';
  40. title2 ' ';
  41.  
  42. ods listing style=ocean ;
  43.  
  44. /* Create the graph with the SGPLOT procedure. Each SERIES statement
  45.   produces a line and the NEEDLE statement produces the needle in the graph. */
  46. proc sgplot data=yield cycleattrs;
  47. series x=mat1yr y=yld1yr / markers
  48. markerattrs=(symbol=circlefilled size=10px)
  49. lineattrs=(pattern=solid) name='n1';
  50. series x=mat1mo y=yld1mo / markers
  51. markerattrs=(symbol=circlefilled size=10px)
  52. lineattrs=(pattern=solid) name='n2';
  53. series x=matcur y=yldcur / markers
  54. markerattrs=(symbol=circlefilled size=10px)
  55. lineattrs=(pattern=solid) name='n3';
  56. needle x=matcur y=yldcur / lineattrs=graphreferenence;
  57. yaxis grid label='Bond Yield';
  58. xaxis type=linear values=(1 2 3 6 7 8 9 11 14) label='Bond Maturity';
  59. keylegend 'n1' 'n2' 'n3' / position=top noborder;
  60. run;
  61. title;
  62. title2;

Report this snippet  

You need to login to post a comment.