BookmarkSubscribeRSS Feed
Bhupi
Fluorite | Level 6

Hi,

I am using GCHART to produce clustered stacked bar chart using the following code. I want to show data labels (percentage of total as rounded without % sign) of individual components within a vertical bar along with letter grouping that is available in the dataset as an individual column with letters for each observation. The first issue I am not able to resolve is that what changes I need to make in the following code to make it rounded percentages without % sign. I have used Inside=subpct option. I am using 9.3 TS1M2.

Here is the code!

Data barlabel;                                                                                                                         
length group $15 midpoint $10 Labels $3;
                                                                                               
   retain xsys ysys '2' color 'black' when 'a';                                                                                        
   set DM;                                                                                                                       
    function='label';                                                                                                                   
    midpoint=cultivar;
group=SamplingN;
    subgroup=Part;
    position="8"; 
    text=labels;
color="black";
size=1;
run; 

/* Generate vertical bar chart */
goptions htext=1.6 htitle=2 Ftitle="Times New Roman" Ftext="Times New Roman";
options orientation=Landscape;

/*ods listing image_dpi=450;
ods html close;
ods graphics /noborder imagefmt=jpeg ANTIALIASMAX=6300 ; */
Proc gchart data=DM;
by year;
where SamplingN;
   vbar Cultivar / discrete noframe
     group=SamplingN
                 subgroup=Part
     sumvar=DM
     Space=2
/*     anno=barlabel*/
     Inside=subpct
/*     Width=6
     Gspace=5 */

raxis=axis1 maxis=axis2 gaxis=axis3 legend=legend1;
axis1 label=(a=90 f="Times New Roman" h=4pct "Dry matter (Mg/ha)" ) value=(f="Times New Roman" h=3pct) order=0 to 12 by 2 minor=none;
axis2 label=none value=(f="Times New Roman" h=2pct);
axis3 label=none value=(f="Times New Roman" h=2.7pct);
legend1 position=(top left inside) across=1 order= ("PL" "LL" "Head" "FL" "Stem") noframe label=none value=(f="Times New Roman" j=l) shape=bar(5,2);
Run;

Thanks for the help!

Bhupinder

Message was edited by: Bhupinder Farmaha

2 REPLIES 2
ballardw
Super User

It looks like part of your code has been dropped. You may want to paste into a pure text editor such as Notepad before copying and pasting here.

GraphGuy
Meteorite | Level 14

How are you creating the variable called 'labels' (that you use in the annotated text=labels)?

If you have a numeric variable that has percent values in it (such as foo=.20 for 20%), then you can set the annotated text as follows...

If you *do* want the % sign, then apply a percent format, something like:

text=put(foo,percentn7.2);

If you do *not* want the % sign in the annotated text, then multiply by 100, something like ...

text=put(foo*100,comma7.0);

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
  • 2 replies
  • 1065 views
  • 0 likes
  • 3 in conversation