I was thinking again about the labeling of the x axis to 52 and >=53, so I found a way of doing this using the VALUESFORMAT= option on the XAXIS statement.
I also had a closer look at your orginal graph and noticed that there is actually a bar between 52 and >=53
Anyway find below the code sample for the x axis labeling as it was in the original graph
/*Create Format*/
data dayToWeek;
attrib
fmtname informat=$10.
hlo informat=$1.
label informat=$3.
;
drop i;
retain
fmtname 'dayToWeek' SEXCL 'Y' EEXCL 'N' HLO '' TYPE 'N'
;
do i = 0 to 52;
start = i*7;
end = (i+1)*7;
label = put(i, z2.);
output;
end;
start=371;
label = '53';
HLO = 'H';
EEXCL = 'N';
output;
run;
proc format cntlin=dayToWeek;
run;
/*Create fake data*/
data Hist(drop=i);
label T = "Days";
call streaminit(1);
do i = 1 to 1000;
T = rand("Normal", 120, 90); /* normal with mean 220 */
T = round(T, 1); /* round to nearest day */
output;
end;
run;
proc freq data=hist( where = ( T>0 )) NOPRINT;
tables T / out=work.hist_bin;
format T dayToWeek.;
run;
*
* convert the bin week to the real week number
*;
data hist_bin2;
set hist_bin;
t2 = input( vvalue(t), 8.);
run;
*
* create an all weeks data set
*;
data allWeeks;
do t2 = 1 to 53;
output;
end;
run;
*
* merge data and all weeks
* convert t to char
*;
data hist_bin_all;
merge hist_bin2 allWeeks;
by t2;
tc = put(t2, z2.);
run;
*
* create a format for labeling the x axis
*;
proc format;
value $tc_display
"04" = "4"
"08" = "8"
"12" = "12"
"16" = "16"
"20" = "20"
"24" = "24"
"28" = "28"
"32" = "32"
"36" = "36"
"40" = "40"
"44" = "44"
"48" = "48"
"52" = "52"
"53" = "(*ESC*){unicode '2265'x}53"
other = " "
;
run;
title 'Length of Travel';
ods graphics / width=1600 height=800;
proc sgplot data=work.hist_bin_all;
vbar Tc / response=percent;
xaxis
label="Duration (Weeks)"
valuesformat=$tc_display.
;
yaxis label="Percent";
run;
Bruno
... View more