BookmarkSubscribeRSS Feed
Whitlea
Obsidian | Level 7

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!

 

1 REPLY 1
Whitlea
Obsidian | Level 7

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;

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1063 views
  • 0 likes
  • 1 in conversation