BookmarkSubscribeRSS Feed
Calcite | Level 5


Please find the below code for the graph. I need subgroup in this order if prodnum >=40 then this should come first and if prodnum <40 then second.

Currently prodnum in subgroup is ordered that is 2 14 18 40 44 50 60 70

Desired Output: 40 44 50 60 70 2 14 18

Also note that prodnum is dynamic after 18 you may expect 28 30 35 or any another value which is in chronological order.

Please help me in getting the desired output. Thanks in Advance.

  /* Set the graphics environment */                                                                                                     

goptions reset=all cback=white border htitle=12pt htext=10pt;                                                                          

/* Define the title */                                                                                                                 

title1 "Side-by-Side Subgrouped Bar Chart";                                                                                          

/* Define the axis characteristics */                                                                                                  

axis1 value=none label=none;                                                                                                         

axis2 label=(angle=90 "Actual Sales");                                                                                               

axis3 label=none;                                                                                                                    

/* Define the legend options */                                                                                                        

legend1 frame;                                                                                                                       

/* Generate the graph */                                                                                                               

proc gchart data=prodsale1;                                                                                                      

   vbar prodnum / subgroup=prodnum group=country sumvar=actual                                                                          

                  legend=legend1 space=0 gspace=4                                                                                       

                  maxis=axis1 raxis=axis2 gaxis=axis3;                                                                                  



Meteorite | Level 14

"(Almost) any problem can be solved by a layer of indirection"  Smiley Happy

You can include some numeric values in your data, that are in the desired order, and then create a user-defined format to make those numeric values print as the desired text/numbers.  Here's a stripped-down example, with just the essentials:

data mydata;

input bar $ 1 desired_order desired_text value;


A 1 40 1

A 2 44 1

A 3 50 1

A 4 60 1

A 5 70 1

A 6 2 1

A 7 14 1

A 8 18 1



/* User-defined format to get subgroups in desired order */

proc sql; create table foo as select unique desired_order, desired_text from mydata; quit; run;

data control; set foo (rename = ( desired_order=start desired_text=label));

fmtname = 'subfmt';

type = 'N';

end = START;


proc format lib=work cntlin=control;


proc gchart data=mydata;

format desired_order subfmt.;

vbar bar / type=sum sumvar=value



Calcite | Level 5


Thanks for your code.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1 like
  • 2 in conversation