BookmarkSubscribeRSS Feed
TSAS2
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?

 

BR

TSAS

3 REPLIES 3
svh
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?
https://sasnrd.com/sas-tmplout-option/
DanH_sas
SAS Super FREQ

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.

 

TSAS2
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.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 811 views
  • 0 likes
  • 3 in conversation