BookmarkSubscribeRSS Feed
sugiyama
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;

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.

 

6 REPLIES 6
Reeza
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.

Reeza
Super User

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

 

 

DanH_sas
SAS Super FREQ

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

Rick_SAS
SAS Super FREQ

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.

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

 

 

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.

 

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

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 6 replies
  • 4739 views
  • 2 likes
  • 4 in conversation