Hi,
I have this code
data have;
input study_name $ June July August;
datalines;
A 20 16 39
B 18 18 6
C 19 1 5
D 87 65 115
E 63 55 62
F 81 104 87
G 73 19 49
H 189 69 79
I 28 6 8
J 87 83 52
K 0 0 0
L 0 0 0
M 4 1 1
N 1 0 2
O 212 159 304
;
proc transpose data=have out=trans
name=Month;
by study_name;
var June July August;
run;
Proc sgplot data=trans;
vbar month / response=col1 group=study_name;
yaxis grid display=(nolabel);
Xaxis display=(nolabel);
run;
which produces this result in the picture.
Note that the months in the bar chart are not displayed as they are in their order, they have alphabetical order.
I tried to find an option to change that but I couldn't find. Also, I don't need to display the study_name in the chart and don't know how to change the default.
Add DISCRETEORDER=DATA to your XAXIS statement, and set the legend title to be "".
roc sgplot data=trans;
vbar month / response=col1 group=study_name;
yaxis grid display=(nolabel);
Xaxis display=(nolabel) discreteorder=data;
keylegend / title="";
run;
Hope this helps!
Dan
It is always better to use numbers to represent calendar or clock values. So if June is 6 and July is 7 and August is 8, these will automatically plot in the desired order.
Also, instead of data as you have shown it, you could do less programming if you re-organzied the data before you create the SAS data set, something like
data have;
input study_name $ month value;
datalines;
A 6 20
A 7 16
A 8 39
B 6 18
Add DISCRETEORDER=DATA to your XAXIS statement, and set the legend title to be "".
roc sgplot data=trans;
vbar month / response=col1 group=study_name;
yaxis grid display=(nolabel);
Xaxis display=(nolabel) discreteorder=data;
keylegend / title="";
run;
Hope this helps!
Dan
@DanH_sas wrote:
Add DISCRETEORDER=DATA to your XAXIS statement, and set the legend title to be "".
roc sgplot data=trans; vbar month / response=col1 group=study_name; yaxis grid display=(nolabel); Xaxis display=(nolabel) discreteorder=data; keylegend / title=""; run;
Hope this helps!
Dan
It might help get the right plot, but it is still a better practice to use numbers for calendar time periods rather than words like "August","June","July". Then, the discreteorder option is not needed. And there are many other potential benefits as well in the long run.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.