Paired Bar Chart


/ Published in: SAS
Save to your folder(s)



Copy this code and paste it in your HTML
  1. %let name=bar4;
  2. filename odsout '.';
  3.  
  4. /* You have to make some values 'negative' so they'll show up on
  5.   the left side of the zero axis, but you want their labels to
  6.   show the positive value. Use a user-defined format to
  7.   accomplish this. */
  8. proc format; picture posval low-high='000,009'; run;
  9.  
  10. data a;
  11. input ITEM $ 1-6 left right;
  12. format amount posval.;
  13. illusion='Group 1'; amount=-1*left; output;
  14. illusion='Group 2'; amount=right; output;
  15. cards;
  16. ITEM A 41 58
  17. ITEM B 53 51
  18. ITEM C 42 33
  19. ITEM D 23 28
  20. ITEM E 12 17
  21. ITEM F 18 13
  22. ;
  23. run;
  24.  
  25. data a; set a;
  26. length htmlvar $500;
  27. htmlvar='title='||quote(
  28. 'Item: '|| trim(left(item)) ||'0D'x||
  29. 'Group 1: '|| trim(left(left)) ||'0D'x||
  30. 'Group 2: '|| trim(left(right))
  31. )
  32. ||' '||
  33. 'href="bar5.htm"';
  34. run;
  35.  
  36.  
  37. GOPTIONS DEVICE=gif;
  38.  
  39. ODS LISTING CLOSE;
  40. ODS HTML path=odsout body="&name..htm"
  41. (title="Paired-Bar Chart")
  42. style=minimal
  43. gtitle gfootnote
  44. ;
  45. goptions noborder;
  46.  
  47. goptions gunit=pct htitle=6 ftitle="swissb" htext=5 ftext="swiss";
  48.  
  49. axis1 label=none;
  50. axis2 label=none order=(-60 to 60 by 10) minor=none offset=(0,0) value=(h=3pct);
  51.  
  52. pattern1 v=solid color=cxbd0026; /* reddish color */
  53. pattern2 v=solid color=cx43a2ca; /* this is the hex rgb color for mild blue */
  54.  
  55. legend1 label=none position=(bottom) cframe=white
  56. shape=bar(3,3) cborder=white across=2;
  57.  
  58. title "Paired-Bar Chart";
  59. proc gchart data=a;
  60. hbar item / discrete
  61. type=sum sumvar=amount
  62. subgroup=illusion /* this controls the coloring */
  63. nostats
  64. maxis=axis1 /* midpoint axis */
  65. raxis=axis2 /* response/numeric axis */
  66. autoref /* reflines at every major axis tickmark */
  67. clipref /* put reflines 'behind' the bars */
  68. legend=legend1
  69. coutline=same
  70. html=htmlvar
  71. des="" name="&name" ;
  72. run;
  73.  
  74.  
  75. quit;
  76. ODS HTML CLOSE;
  77. ODS LISTING;

URL: http://robslink.com/SAS/democd6/aaaindex.htm

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.