%let gpath='C:\Work\Blogs\Graphically Speaking\2015\Post_31_Nov_30_ResColorHistogram'; %let dpi=200; ods html close; ods listing gpath=&gpath image_dpi=&dpi; /*--Bin the data by cholesterol--*/ data ChBin; label ChBin='Cholesterol'; retain BinInt 10 maxbin 0 minbin 1e6; set sashelp.heart(where=(cholesterol > 80 and cholesterol < 360) keep=Cholesterol Systolic) end=last; if cholesterol ne . then ChBin=BinInt*floor(cholesterol/BinInt); minbin=min(minbin, chbin); maxbin=max(maxbin, chbin); if last then do; call symput("MinBin", minbin); call symput("MaxBin", maxbin); call symput("BinInt", BinInt); end; run; /*%put "Min Bin = &MinBin";*/ /*%put "Max Bin = &MaxBin";*/ /*%put "Bin Int = &BinInt";*/ ods html; proc print data=ChBin(obs=10); var cholesterol ChBin; run; ods html close; /*--Histogram using Bar Chart SAS 9.3--*/ ods graphics / reset width=5in height=3in imagename='ChBin_Bar'; proc sgplot data=ChBin noautolegend; vbar chbin / barwidth=0.9 nooutline; xaxis valueattrs=(size=6); run; /*--Define attributes map data set--*/ data AttrMap; length FillColor $8 LineColor $8; id='Hist'; ghigh=192; /*--High value for Green--*/ rhigh=255; /*--High value for Red--*/ mid=(&minbin + &maxbin) / 2; LineColor='CX000000'; do val=&minbin to &maxbin by &BinInt; value=put(val, 5.0); if val < mid then do; g=ghigh; b=0; r=rhigh*(val-&minbin)/ (mid-&minbin); end; else do; r=rhigh; b=0; g=ghigh*(1-((val-&minbin) - (mid-&minbin))/ (mid-&minbin)); end; fillcolor='CX' || put(r, hex2.) || put(g, hex2.) || put(b, hex2.); output; end; run; ods html; proc print data=AttrMap(obs=100); var id value fillcolor; run; ods html close; /*--Histogram using Bar Chart group colors SAS 9.3--*/ ods graphics / reset width=5in height=3in imagename='Color_Group_Bar'; proc sgplot data=ChBin dattrmap=AttrMap noautolegend; vbar chbin / barwidth=0.9 group=chbin attrid=Hist nooutline; xaxis valueattrs=(size=6); run; /*--Histogram using Bar Chart response colors SAS 9.40M3--*/ ods graphics / reset width=5in height=3in imagename='Color_Resp_Bar'; proc sgplot data=ChBin noautolegend; vbar chbin / barwidth=0.9 colorresponse=chbin colorstat=mean colormodel=(cx00C000 cxFFC000 cxff0000) nooutline; xaxis type=linear; run;