Data visualization with SAS programming

conditonally color a bar, depending on whether it is annegative or positive value

Reply
New Contributor
Posts: 3

conditonally color a bar, depending on whether it is annegative or positive value

Hi,

I am trying to show a bar chart and I want to show negative values as red and positive values as green. How do i do that in bar chart? Is it possible using proc glpot. I have to use a bar chart only. It is a continous variable.

Also, how do I change the font size of the axis tickmarks, not the axis label which I know can be changed using xaxisopts=(labelattrs=pts).

Also, how do I make the position of the barlabel appear in the middle or at the bottom of a bar, instead of the default top position of the bar?

I have a template and i invoke that template in proc sgrender. Can I define a style statement along with define statgraph? How do I use both in the proc sgrender?

PLease help.

Grand Advisor
Posts: 17,439

Re: conditonally color a bar, depending on whether it is annegative or positive value

Please post what you have so far, including sample data so we can replicate your issue and not start from scratch. Additionally, include a picture of what you want as a final result.

 

Have you looked at SGPLOT so far?

New Contributor
Posts: 3

Re: conditonally color a bar, depending on whether it is annegative or positive value

You will have to convert the sample excel file into sas dataset and run it though this program.

 

Below is the code:

 

 

proc template;

define statgraph mean_chart;

begingraph;

 

layout overlay/ yaxisopts=(label="%" linearopts=(viewmin=-.10 viewmax=.10))

xaxisopts=(label="Year and Month" );

 

barchart x=yyyymm y=delta/ dataskin=sheen fillattrs=(color=green) stat=pct barwidth=.50

primary=true name="average" barlabelformat=percent10.1 barlabel=true barlabelattrs=(size=7pt );

bandplot x=yyyymm limitlower=-.02 limitupper=.02 /

legendlabel="95% CLI" name="band1" display=(fill) fillattrs=(color=GraphData4:color)

datatransparency=.7 fillattrs=GraphError

;

 

referenceline y=-.02 /curvelabel=eval(putn(mean(&lcl_m.),'percent10.2')) lineattrs=(color=red pattern=dot) name="lcl_m" legendlabel="-2%";

referenceline y=+.02 /curvelabel=eval(putn(mean(&ucl_m.),'percent10.2')) lineattrs=(color=blue pattern=dot) name="ucl_m" legendlabel="+2%";

discretelegend "lcl_m" "ucl_m" ;

 

endlayout;

endgraph;

end;

proc sgrender data=data template=mean_chart;

run;

 

Ask a Question
Discussion stats
  • 2 replies
  • 216 views
  • 0 likes
  • 2 in conversation