Cross post with the main community -
Im not a master of annotate so this may be simple. However, is there a way to SAS write the word Goal on a specific bar in a SAS bar graph? We are doing this for accessibility reasons. The bar is already colored coded red and we would like the word goal appear in the bar in white text.
Thanks for any help!
EJ
Yes, the easiest would be with the annotate.
if you provide a sample code, then I can figure it out.
But in a nut-shell:
Something like this:
data anno;
length color function $8;
retain xsys ysys '2' hsys '4' when 'a'
color 'black' size 5;
set sashelp.class;
if sex = "M" then do;
function = "label"; color = "red" ;style = '"Arial/bold"' ; position = "2"; size = 1.2 ;
text = "Goal";midpoint = sex;
output;
end;
run;
proc gchart data = sashelp.class ;
vbar sex/anno = anno
sumvar = age
;
run;quit;
Is this sort of what you'd like?
Anca.
Or similarly, something like this ... for an hbar:
data my_data; set sashelp.class;
if name='Robert' then goal='y';
else goal='n';
run;
data my_anno; set my_data (where=(goal='y'));
xsys='2'; ysys='2'; hsys='3'; when='a';
function='label'; position='6'; text='goal';
midpoint=name; x=weight/2;
run;
pattern1 v=s c=cxccccff;
pattern2 v=s c=pink;
proc gchart data=my_data anno=my_anno;
hbar name / type=sum sumvar=weight descending subgroup=goal;
run;
Thanks for the responses ... Rob we use your site with the graph example all the time!
The desired result is actually a combination of the two. The results need to be vertical bars with Goal labeled within the bar (in white). Here is where I cant wrap my mind around is that we are graphing multiple versions of the graph depending on the measures being graphed -- the number of bars will vary as will the actual value of the goal. Does SAS handle the proportions of the text? Is it static or in proportion to the width / height of the bar?
EJ
Hi.
Without a specific example, I don't have a ready code, but yes, it is possible to for SAS to handle proportions of the text. If you have prior knowledge of what the 'goal' is for each graph, then you can use a macro to create sepcific annotate data sets for specific graphs.
%macro test(var = , value = );
data anno;
length color function $8;
retain xsys ysys '2' hsys '4' when 'a'
color 'black' size 5;
set sashelp.class;
if &var. = "&value." then do;
function = "label"; color = "red" ;style = '"Arial/bold"' ; position = "2"; size = 1.2 ;
text = "Goal";midpoint = sex;
output;
end;
run;
proc gchart data = sashelp.class ;
vbar sex/anno = anno
sumvar = age
;
run;quit;
%mend test;
%test(var = sex, value = M);
%test(var = sex, value = F);
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.