BookmarkSubscribeRSS Feed
Fluorite | Level 6

I am having a problem using the categoryorder option in a sgplot procedure with a vbar statement and a response variable. My variable CNT is a three-character discrete variable, my PV1Math variable is a numeric variable. What I want to do is to replicate what I can easily do in SAS/Graph with SGPLot.


I have some students who have Windows 9.4 TS1M3 and have SAS/Graph and other students who are using SAS UE and thus do not have access to SAS/Graph. I want to have them do homework assignments and produce similiar results.


For SAS/Graph, I get what I want with:


proc gchart data=one;

     vbar cnt / sumvar=pv1math type=mean descending;



But what I believe should give me the equivalent result using SGPLOT is giving me an error.


proc sgplot data=one;

      vbar cnt / response=pvt1math stat=mean categoryorder=respdesc;



I get: WARNING: The data for a BARCHARTPARM statement are not appropriate. The BARCHARTPARM statement expects summarized data. The bar chart might not be drawn correctly.


In fact, I do get a bar chart that is not drawn correctly.


I am surprised as the SAS 9.4 ODS Graphics Procedure Guide, Fifth Edition, on page 1014 says I am supposed to have a response variable to use the categoryorder option. Additionally, as I am using VBAR I don't need to use summarized data. VBARPARM does require summarized data, so it appears as if the procedure is confusing VBAR and VBARPARM.


I know I can fix the problem with an xaxis statement and value option to force the bars to be descending in values. I am trying not to have to teach too different things to SAS UE students and SAS/Graph students.(I don't want to have them use xaxis or learn Graph Template Language.)


I don't see my issue as a known bug. I wanted to make sure I was interpretting things correctly.


Super User

Can you post your full log?


And some sample data and a pic of the graph you're trying to achieve. I'm not good at visualizing graphs without a template.

Super User

And what version of SAS are you testing this on to get your error?




Actually, RESPONSE is not required for CATEGORYORDER to work. Try these two simple programs and see if they work for you:


proc sgplot data=sashelp.class;
vbar age / categoryorder=respdesc;

proc sgplot data=sashelp.class;
vbar age / categoryorder=respdesc response=weight stat=mean;

I agree with Reeza that some sample data and/or the PROC CONTENTS output would be helpful, as it sounds like a data issue.





In addition to Dan's example, see the article "Bar chart with response sort".  The Graphically Speaking blog has other examples, which you can see by typing 


into the search box on the blog.

Fluorite | Level 6

Thank for the responses. I have done some more testing. The appears to be related to the fact that the variable that I am using has a user defined format associated with it. Below is the graph before I attempt to graph the bars from high to low based on the average math scores by country.





When I add the categoryorder option, I get this:




This is the warning message I get: 

sgplot problem Log warning.jpg


Now it turns out that my CNT variable in my data set has a format associated with it: $CNTF. (I have to read in the formats to be able to do the first graph.)


If I add a format statement "format cnt $cntf." in my procedure then the categoryorder works fine.


proc sgplot data=two ;
     vbar cnt / response=pv1math stat=mean categoryorder=respdesc;
     format cnt $cntf.;


It is strange that without the categoryorder option and a response variable, everything is fine, and I don't need a format statement. When I do the exact same thing but add the categoryorder I get problems. 


When I have checked examples of sgplot and vbar with categoryorder, I believe there were no formats involved.


I have attached my code, log, and output in pdf files if anyone is curious. It has a proc contents, proc print, and the format definitions that apply to my problem.


Super User

Do you have a quit after your sgplot and gplot procs?

Also, is the format already applied on your dataset?

Otherwise I don't see it used anywhere else...




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