This is my first time dealing with annotation.
I have decided to utilize annotation because I will be generating several graphs and I want to be sure I don't have issues with my error bars running into my labels. Ideally, I would like my labels to be located inside the bars at the base of each bar.
I am trying to insert labels (data labels) into my proc template barchartparm. Is it possible to do this with drawtext if i am using values of a variable for my bar labels ?
proc template;
define statgraph district;
begingraph / datacolors=(white CXEBDDED CXEBDDED CXEBDDED CXEBDDED CXEBDDED CXEBDDED CXEBDDED) ;
layout overlay / walldisplay=(fill) xaxisopts=(display=( line tickvalues)
DISCRETEOPTS=(TICKVALUEFITPOLICY =split))
yaxisopts=( offsetmin=0 linearopts=(viewmin=0 viewmax=100 tickvaluelist=(0 50 100)));
/* drawtext textattrs=(size=8pt) "variable" /width=5 widthunit=percent xspace=datavalue yspace=graphpercent x=2*/
/* y=80 justify=center;*/
barchartparm x=district y=percent / group=district groupdisplay=cluster errorupper=uppct errorlower=lowpct
ERRORBARATTRS=(color=black)
OUTLINEATTRS=(color=black) ;
/* scatterplot y=percent x=district / datalabel=percent */
/*DATALABELPOSITION=topright DATALABELATTRS=GRAPHVALUETEXT(SIZE=10pt weight=bold)
markerattrs=(size=0) ;*/
annotate;
endlayout;
endgraph;
end;
run;
proc sgrender data=district template=district sganno=anno;
format district district.;
run;
the following code inserts "variable" into my graph. I want it to insert percent values from my variable.
drawtext textattrs=(size=8pt) "variable" /width=5 widthunit=percent xspace=datavalue yspace=graphpercent x=2
y=80 justify=center;
I have also tried using an annotated data set which gave me the following error.
NOTE: FUNCTION=label in the annotation data set is invalid.
Code:
data anno;
length function color text $ 8;
retain function 'label' color 'black' when 'a'
xsys ysys '2' position '2' size 3 hsys '3';
set district;
midpoint=&VAR.;
group=district;
function='label'; xsys='2'; ysys='2'; x=midpoint; y=0; text=left(put(percent,4.1)); size=5; output;
run;
Can anyone tell me the best way to go about doing this?
Thanks!
I just found a way around the annotated data set by using an additional scatterplot ...
data District;
set desc_out;
dataloc=lowpct-2;
run;
proc template;
define statgraph district;
begingraph / datacolors=(white CXEBDDED CXEBDDED CXEBDDED CXEBDDED CXEBDDED CXEBDDED CXEBDDED) ;
layout overlay / walldisplay=(fill) xaxisopts=(display=( line tickvalues)
DISCRETEOPTS=(TICKVALUEFITPOLICY =split))
yaxisopts=( offsetmin=0 linearopts=(viewmin=0 viewmax=100 tickvaluelist=(0 50 100)));
barchartparm x=district y=percent / group=district groupdisplay=cluster errorupper=uppct errorlower=lowpct
ERRORBARATTRS=(color=black)
OUTLINEATTRS=(color=black) ;
scatterplot y=dataloc x=district / markercharacter=percent ;
endlayout;
endgraph;
end;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.