I would like for my vbar chart to be sorted in descending order using Officers as the variable. I tried using proc sort under data but it did not work for vbar. Alternatively, I tried sorting using a by statement in proc sgplot and what I got in return were 21 singular charts. I am a little stumped as to what I am doing wrong.
Can anyone help? Any help is very much appreciated!
You said: "I tried using proc sort under data but it did not work for vbar. Alternatively, I tried sorting using a by statement in proc sgplot and what I got in return were 21 singular charts." Your instinct to do a sort was correct, but your approach -- to use a "BY statement in PROC SGPLOT" or a "PROC SORT under DATA" -- was flawed.
Using a BY statement in any procedure or DATA step does not actually PERFORM the sort -- it only uses the sorted data -- generally, as you saw, to treat each BY group as a unit to be handled separately -- such as when you got 21 separate charts. I'm not sure what you mean by saying you tried PROC SORT "under" a DATA I suspect you mean that you added a PROC SORT in the code after your DATA step where you created the POLICE dataset -- this was CORRECT, if you had this:
proc sort data=police;
by descending Officers;
which produces a sorted version of the POLICE dataset with the rows organized in descending order based on the value of the OFFICERS variable.
The next thing would be to look up the XAXIS statement for PROC SGPLOT -- you can control the order of the XAXIS or YAXIS (from the default) by using options on the XAXIS or YAXIS statement. The option you would be interested in for the XAXIS would be the DISCRETEORDER= option (since the XAXIS is a "discrete" axis with one bar for every value of the character variable COUNTY).
When I do transparent overlays, I like to make the "underneath" bar a little bigger and make the "on top" bar the transparent bar, as shown below.
ps -- in the future, you might want to post SGPLOT questions in the ODS GRAPHICS and SAS/GRAPH forum
proc sgplot data=Police;
xaxis label="County" discreteorder=data;