Reputation: 69
a very simple question... I'm trying to plot some data with sgplot. On the x-axis I should have: t0, t6, t12, t18 but sas orders as follows: t0, t12, t18, t6. I tried to manually set the desired order and I also tried to sort the data by the column containing t* labels following the desired order but nothing happens. Can anyone help me to solve this issue?
Thank you in advance
Upvotes: 0
Views: 1877
Reputation: 12909
Use the xaxis values=
statement to specify your order. For example:
data have;
input t$ value;
datalines;
t0 1
t12 10
t18 30
t6 4
;
run;
proc sgplot data=have;
vbar t / response=value;
xaxis values=('t0' 't6' 't12' 't18');
run;
If you have a lot of these, you can read the order all into a macro variable by extracting the numeric part of each value of t
, then convert it to a numeric variable for sorting.
data set_order;
set have;
/* Get only the numeric part */
t_order = input(compress(t,,'A'), 8.);
run;
proc sort data=set_order;
by t_order;
run;
proc sql noprint;
select quote(t)
into :t separated by ' '
from set_order;
quit;
proc sgplot data=have;
vbar t / response=value;
xaxis values=(&t.);
run;
Upvotes: 2