Hi there,
I work with SAS 9.3 and want to generate a waterfall chart with grouped data. I’m using proc template and sgrender.
The downwards bar I want to display with the red color, the ascending bar with the green color.
I want to use the statement “fillattrs=(COLOR=GREEN CONTRASTCOLOR=RED)” but I make something wrong, it don’t works…. 😞
Do you have an idea what’s wrong or circumvention for this problem?
Thank you very much for your help.
Brigitte
~~~~~~~~~~~~~~~~ code ~~~~~~~~~~~
data WORK.DATA_GRAPH;
input MONAT_TXT $ KER_GESAMT_IST_AJ POSNEG;
datalines;
Jan2011 288425 1
Feb2011 -280884 0
Mar2011 652716 1
Apr2011 200244 1
May2011 27043 1
Jun2011 415841 1
Jul2011 -308976 0
Aug2011 -46304 0
Sep2011 474226 1
;
run;
proc template;
define statgraph KER_GRAPH_WATERFALL ;
begingraph / designheight = 600 designwidth = 1200 border = false;
entrytitle _id='title' halign=left 'Jahresverlauf operatives Ergebnis' / textattrs=(weight=bold style=normal size=9 family='Arial');
layout overlay;
waterfallchart category=MONAT_TXT response=KER_GESAMT_IST_AJ /
colorgroup=POSNEG fillattrs=(COLOR=GREEN CONTRASTCOLOR=RED)
barlabel=true dataskin=gloss
datalabelattrs=(color=BLACK style=NORMAL family='Arial' size=9)
;
endlayout;
endgraph;
end;
proc sgrender data = WORK.DATA_GRAPH
template = KER_GRAPH_WATERFALL ;
run;
The way to do this is to use a discrete attributes map. It gives you the ability to assign attributes to specific values. Notice in the code below that I use the new ATTRVAR called SIGNVAR instead of the POSNEG variable for the COLORGROUP so that the map is used by the waterfall chart.
Hope this helps!
Dan
proc template;
define statgraph KER_GRAPH_WATERFALL ;
begingraph / designheight = 600 designwidth = 1200 border = false;
discreteattrmap name="colorbysign";
value '0' / fillattrs=(color=red);
value '1' / fillattrs=(color=green);
enddiscreteattrmap;
discreteattrvar attrvar=signvar var=posneg attrmap="colorbysign";
entrytitle _id='title' halign=left 'Jahresverlauf operatives Ergebnis' / textattrs=(weight=bold style=normal size=9 family='Arial');
layout overlay;
waterfallchart category=MONAT_TXT response=KER_GESAMT_IST_AJ / colorgroup=signvar
barlabel=true dataskin=gloss datalabelattrs=(color=BLACK style=NORMAL family='Arial' size=9);
endlayout;
endgraph;
end;
The way to do this is to use a discrete attributes map. It gives you the ability to assign attributes to specific values. Notice in the code below that I use the new ATTRVAR called SIGNVAR instead of the POSNEG variable for the COLORGROUP so that the map is used by the waterfall chart.
Hope this helps!
Dan
proc template;
define statgraph KER_GRAPH_WATERFALL ;
begingraph / designheight = 600 designwidth = 1200 border = false;
discreteattrmap name="colorbysign";
value '0' / fillattrs=(color=red);
value '1' / fillattrs=(color=green);
enddiscreteattrmap;
discreteattrvar attrvar=signvar var=posneg attrmap="colorbysign";
entrytitle _id='title' halign=left 'Jahresverlauf operatives Ergebnis' / textattrs=(weight=bold style=normal size=9 family='Arial');
layout overlay;
waterfallchart category=MONAT_TXT response=KER_GESAMT_IST_AJ / colorgroup=signvar
barlabel=true dataskin=gloss datalabelattrs=(color=BLACK style=NORMAL family='Arial' size=9);
endlayout;
endgraph;
end;
Hi Dan,
thank you very much for this successful solution. I learned a lot !
Have a nice day,
Brigitte
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.