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;
"(Almost) any problem can be solved by a layer of indirection"
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;
Hi,
Thanks for your code.
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!
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.