BookmarkSubscribeRSS Feed
Calcite | Level 5

Hi all,

Normally I am using VBAR from the SGPLOT Procedure to create single bar charts.  Now I want to build a chart matrix with several plots using the SAS Graph template. Everything works fine except that I can not replicate some functionality from VBAR statement with the BARCHART Statement.

I want to order a stacked bar chart in a descending order, which means the bars should be ordered from the largest to the smallest, as well as each stacked bar should be ordered by the size of each categorical level.

VBAR provides the “CATEGORYORDER = RESPDESC” option which solves my problem, but the same option is not working with the BARCHART Statement. Does anyone knows a workaround which leads to the same solution?




Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
Have you tried using the statement that helps find code for SAS Graph Template that can replicate something SGPLOT does?

The SGPLOT and SGPANEL procedures do some extra processing to support this feature. There is not a direct option in GTL to do it. To do this GTL, there four key items:

  1. Pre-summarize your data using PROC MEANS or PROC SUMMARY
  2. Sort the data in ascending or descending order using PROC SORT
  3. Use a BARPARM statement to render the bar chart in GTL
  4. On the category axis (either X to Y), specify SORTORDER=DATA in the DISCRETEOPTS

Let me know if you still have issues.


Calcite | Level 5

I solved my issue. I forgot to mention that my dataset contains two columns with data which need so be sorted independently first. @ DanH_sas your suggestion did not work completely for my problem but put me on the right track. Thanks for that! I solved my issue by following your logic with proc sql in advance.


Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.


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.

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
  • 3 replies
  • 3 in conversation