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.



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