BookmarkSubscribeRSS Feed
DELI
Calcite | Level 5

Hi, we are trying to use sgplot varbar ,

option:     vbar x / response =y   stat=mean datalabel ;

to put mean data above  each bar. however, we found we have no way to format datalabel.

Is there a way to format datalabel to avoid long tail of the mean?

We tried to format response Y. But it seems sgplot   gave a mean  based on formatted Y,   lacking original precision.

ie. after formating Y, MEAN=2.12,  but using the real numbers Mean=2.13,  how we solve this?

hard to pass QC.

ANY IDEA HOW TO SOLVE THIS?

Thank you!

7 REPLIES 7
DanH_sas
SAS Super FREQ

What version of SAS are you using?

DELI
Calcite | Level 5

I am using SAS9.2  ON WIN7

djrisks
Barite | Level 11

Hi,

If you are using SAS 9.2 (or 9.3) you can use Graph Template Language with the plot statement barchart along with the option barlabelformat. If you need any more assistance please let me know.

Many thanks,

Kriss Harris

DanH_sas
SAS Super FREQ

Are you getting the 2.13 if you use PROC MEANS?

DELI
Calcite | Level 5

Thank you all,

   Our QC people found the issue. they compare the values from tabulate against the graph from SGPLOT.

we used picture format .

   If use means, i figure it will be same thing.  may be i can get it done using GTL, but need to start afresh from syntax.

Is there easy ways to get it done.

PROC FORMAT;
   PICTURE TAB (ROUND) 
     1000000 - <10000000= "09999999" 
      100000 - <1000000 = "0999999" 
       10000 - <100000  = "099999" 
        1000 - <10000   = "09999" 
         100 - <1000    = "0999" 
          10 - <100     = "099.9" 
           1 - <10      = "09.99" 
          .1 - <1       = "9.999"
         .01 - <0.1     = "9.9999"
        .001 - <0.01    = "9.99999"
       .0001 - <0.001   = "9.999999"
      .00001 - <0.0001  = "9.9999999"
     .000001 - <0.00001 = "9.99999999"
    .0000001 - <0.000001= "9.999999999"

   -10000000 - <-1000000= "09999999"  (PREFIX="-")
    -1000000 - <-100000 = "0999999"  (PREFIX="-")
     -100000 - <-10000  = "099999"  (PREFIX="-")
      -10000 - <-1000   = "09999"  (PREFIX="-")
       -1000 - <-100    = "0999" (PREFIX="-")
        -100 - <-10     = "099.9"  (PREFIX="-")
         -10 - <-1      = "09.99"  (PREFIX="-")
          -1 - <-0.1      = "9.999"(PREFIX="-")
         -.1 - <-0.01     = "9.9999"(PREFIX="-")
        -.01 - <-0.001    = "9.99999"(PREFIX="-")
       -.001 - <-0.0001   = "9.999999"(PREFIX="-")
      -.0001 - <-0.00001  = "9.9999999"(PREFIX="-")
     -.00001 - <-0.000001 = "9.99999999"(PREFIX="-")
    -.000001 - <-0.0000001= "9.999999999"(PREFIX="-")
  ;

Jay54
Meteorite | Level 14

proc template;
  define statgraph mean;
    begingraph;
      entrytitle 'Mean Mileage by Type';
      layout overlay;
         barchart x=type y=mpg_city / stat=mean
                       barlabel=true barlabelformat=4.1;
       endlayout;
     endgraph;
  end;
run;

ods listing;
ods graphics / reset width=5in height=3in imagename='mean';
proc sgrender data=sashelp.cars template=mean;
run;

mean.png

xxformat_com
Barite | Level 11

I would suggest to store the rounded values in a variable and add this variable after datalabel=.

 

proc format;
   picture twodigits (round) low-high='009.99';
run;

proc sql;
	create table class as
    select sex, height, put(mean(height),twodigits.) as mean_height
    from sashelp.class
    group by sex;
quit;

*before;
proc sgplot data=class;
    vbar sex / response =height stat=mean datalabel;
run;

*after;
proc sgplot data=class;
    vbar sex / response =height stat=mean datalabel=mean_height;
run;

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 5888 views
  • 0 likes
  • 5 in conversation