Reputation: 1537
The default options for grouporder
is data
. But if my data starts with Sat
and different colors are assigned to Sat
,Sun
etc, then the legend order either begins with Sat(input data order)
or with alphabetical order.
But I want to force the order to be Mon - Sun
. Of course I can create another variable myorder 1 for Mon
and 7 for Sun
then group by myorder. But in this way the legend shows 1,2,3..
instead of Mon Tue ...
sample data:
Date DayofWeek myorder Sale
3Jan15 Sat 6 20.1
4Jan15 Sun 7 31.1
5Jan15 Mon 1 19.1
This may be a solution
But I tried proc format
(the method used in the above link)but it doesn't help.
Sample data:
data _t;
input day dow $ sale;
cards;
1 Thu 22.0
2 Fri 23.1
3 Sat 28.2
4 Sun 30.0
5 Mon 21.1
6 Tue 18.2
7 Wed 16.9
8 Thu 18.0
9 Fri 27.9
10 Sat 27.2
11 Sun 13.9
12 Mon 16.0
13 Tue 18.0
;
run;
Upvotes: 1
Views: 2098
Reputation: 63424
The PROC FORMAT solution is effective. Here's an example. It would be nice if preloadfmt
existed as an option here, but it doesn't seem to.
Basically we create two formats - an informat (to convert 'Sun' to 1 etc.) and a format (to label 1 with 'Sun'). I name them the same, they don't have to be.
proc format;
value dayorder
1='Sun'
2='Mon'
3='Tue'
4='Wed'
5='Thu'
6='Fri'
7='Sat'
;
invalue dayorder
'Sun'=1
'Mon'=2
'Tue'=3
'Wed'=4
'Thu'=5
'Fri'=6
'Sat'=7
;
quit;
data _t2;
set _t;
dow_order = input(dow,dayorder.);
format dow_order dayorder.;
run;
proc sgplot data=_t2;
vbar day/group=dow_order response=sale grouporder=ascending;
run;
Upvotes: 1