Data visualization with SAS programming

Error with Proc SGPLOT, Vbar, Response, and categoryorder=respdesc;

Reply
New Contributor
Posts: 4

Error with Proc SGPLOT, Vbar, Response, and categoryorder=respdesc;

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;

quit;

 

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;

run;

 

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.

 

Grand Advisor
Posts: 16,378

Re: Error with Proc SGPLOT, Vbar, Response, and categoryorder=respdesc;

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.

Grand Advisor
Posts: 16,378

Re: Error with Proc SGPLOT, Vbar, Response, and categoryorder=respdesc;

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

 

 

SAS Super FREQ
Posts: 864

Re: Error with Proc SGPLOT, Vbar, Response, and categoryorder=respdesc;

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.

 

Thanks!

Dan

SAS Super FREQ
Posts: 3,233

Re: Error with Proc SGPLOT, Vbar, Response, and categoryorder=respdesc;

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 

CATEGORYORDER

into the search box on the blog.

New Contributor
Posts: 4

Re: Error with Proc SGPLOT, Vbar, Response, and categoryorder=respdesc;

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.

 

 

SGPlot11.png

 

When I add the categoryorder option, I get this:

 

SGPlot13.png

 

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.;
run;

 

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.

 

Grand Advisor
Posts: 16,378

Re: Error with Proc SGPLOT, Vbar, Response, and categoryorder=respdesc;

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

 

Post a Question
Discussion Stats
  • 6 replies
  • 249 views
  • 2 likes
  • 4 in conversation