11-03-2016 04:38 PM
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.
11-03-2016 04:55 PM
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.
11-03-2016 05:20 PM
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; run; proc sgplot data=sashelp.class; vbar age / categoryorder=respdesc response=weight stat=mean; run;
I agree with Reeza that some sample data and/or the PROC CONTENTS output would be helpful, as it sounds like a data issue.
11-04-2016 09:47 AM
11-04-2016 04:00 PM
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:
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.
11-04-2016 04:33 PM
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...