BookmarkSubscribeRSS Feed
esjackso
Quartz | Level 8

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

4 REPLIES 4
AncaTilea
Pyrite | Level 9

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.

GraphGuy
Meteorite | Level 14

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;

esjackso
Quartz | Level 8

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

AncaTilea
Pyrite | Level 9

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);

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 837 views
  • 6 likes
  • 3 in conversation