BookmarkSubscribeRSS Feed
jacupp711
Calcite | Level 5

I am attempting to create a colored bar chart showing the percentage (from 0% to 100%) of employees who have completed their hours for the year. The report is produced monthly so as the months progress the bars should grow. I would like the colors to go from red (0%) to green (100%). Currently the colors range from red(0%) the the maximum value. With this method the range of values colored would change each month instead of being a static 0-100%. Below is table, script, and graph. Is there anyway to define the color range?

 

jacupp711_0-1633117176159.png

ods graphics / reset width=6in height=4in;
title '% Complete Minimum Credit2';
proc sgplot data=fleet_comp2 nowall noborder;
vbar report_ac / response=perc_comp nostatlabel 
				colorresponse=perc2 colormodel=(red yellow green) barwidth=1;
xaxis display=(nolabel);
yaxis values=(0 to 1 by .1) display=(nolabel) grid;
run;

jacupp711_1-1633117206752.png

 

3 REPLIES 3
ballardw
Super User

I think you would benefit from this example: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n1fxl54aizx1tjn1nfder5bsqqco.htm

 

This is an RATTRMAP example where you provide an additional data set that maps the value ranges to color ranges.

 

Probably your "map" would provide ranges with a minimum and maximum value pair that maps to a specific range of Colormodel 1 to 2 .

I would look at color ranges like:

min max colormodel1   colormodel2

_min_  30 red                orange

30   60    orange          yellow

60  100  yellow          green

GraphGuy
Meteorite | Level 14

Here's some sample code using the rattrmap (range attribute map) solution @ballardw recommended:

 

data fleet_comp2;
length report_ac $3;
format perc_comp perc2 percentn7.2;
input report_ac perc_comp;
perc2=perc_comp;
datalines;
220 .1282
320 .0366
350 .5652
717 .2143
73N .1587
7ER .6269
;
run;

data myrattrmap;
length min max $5 color $30;
input min max color;
id="myID";
datalines;
0 .1 cxa50026
.1 .2 cxd73027
.2 .3 cxf46d43
.3 .4 cxfdae61
.4 .5 cxfee08b
.5 .6 cxd9ef8b
.6 .7 cxa6d96a
.7 .8 cx66bd63
.8 .9 cx1a9850
.9 1 cx006837
;
run;

proc sgplot data=fleet_comp2 nowall noborder rattrmap=myrattrmap;
vbar report_ac / response=perc_comp nostatlabel barwidth=1
				colorresponse=perc2 rattrid=myID;
xaxis display=(nolabel);
yaxis values=(0 to 1 by .1) display=(nolabel) grid;
run;

rattrmap.png

Ksharp
Super User

You want this ?

 

proc freq data=sashelp.class noprint;
table age/out=have;
run;
ods graphics/reset=all;
proc template;
  define statgraph cal_heatmap;
    begingraph ;
	  entrytitle "xxxxxxxxxx";
	  rangeattrmap name="rmap";
        range 0- 100 / rangecolormodel=(green yellow red);		

	  endrangeattrmap;
	  rangeattrvar attrmap="rmap" attrvar=cvar var=percent;
	  layout overlay ;
	    BARCHARTPARM category=age response=percent / FILLTYPE=solid
	    colorresponse=cvar orient=horizontal name="heatmap" ;

		continuouslegend "heatmap" ;
	  endlayout;
	endgraph;
  end;
run;

proc sgrender data=have template=cal_heatmap;
run;

x.png

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1985 views
  • 4 likes
  • 4 in conversation