Data visualization with SAS programming

Is there a way to have SAS write the word "Goal" on a specific bar in a SAS bar graph?

Reply
Super Contributor
Posts: 333

Is there a way to have SAS write the word "Goal" on a specific bar in a SAS bar graph?

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

Super Contributor
Posts: 543

Re: Is there a way to have SAS write the word "Goal" on a specific bar in a SAS bar graph?

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.

SAS Employee
Posts: 967

Re: Is there a way to have SAS write the word "Goal" on a specific bar in a SAS bar graph?

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;

Super Contributor
Posts: 333

Re: Is there a way to have SAS write the word "Goal" on a specific bar in a SAS bar graph?

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

Super Contributor
Posts: 543

Re: Is there a way to have SAS write the word "Goal" on a specific bar in a SAS bar graph?

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

Ask a Question
Discussion stats
  • 4 replies
  • 330 views
  • 6 likes
  • 3 in conversation