BookmarkSubscribeRSS Feed
1239
Calcite | Level 5

Hi,

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;                                                                                  

run;                                                                                                                                   

quit;

2 REPLIES 2
GraphGuy
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;

datalines;

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

;

run;

/* 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;

run;

proc format lib=work cntlin=control;

run;

proc gchart data=mydata;

format desired_order subfmt.;

vbar bar / type=sum sumvar=value

subgroup=desired_order;

run;

1239
Calcite | Level 5

Hi,

Thanks for your code.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 1382 views
  • 1 like
  • 2 in conversation