Please correct me if I miss something because just right now the example is a typical example showing how graph can make the user mad.
In the example two formats are used; one is assigned to the variable using the format statement ; the other one is set using the option tickvalueformat.
My original thought was that tickvalueformat would have priority over the variable format to set the tickvalues and that the variable format would be used to set the order of the bars.
However, in this example, we can see that the tick values are coming from the format assigned to the variable, but the format width is coming from the format given in the tickvalueformat option. As the default format label with of the sex format is 6, tick values are truncated.
proc format;
value $sex 'M'='Male'
'F'='Female';
value $sexnum 'M'='1-Male'
'F'='2-Female';
run;
proc sgplot data=sashelp.class noborder;
vbarbasic sex;
xaxis discreteorder=formatted tickvalueformat=$sex.;
format sex $sexnum.;
run;
proc sgplot data=sashelp.class noborder;
vbarbasic sex;
xaxis discreteorder=formatted tickvalueformat=$sex20.;
format sex $sexnum.;
run;
Have a look at the following code sample. Two format are created, the first one is used for the ordering of the bars, the second one is used to label the tick marks. Note that the second format uses the formatted values as the input value. No truncation takes place.
proc format;
value $sex
'M'='1Male'
'F'='2Female'
;
value $sextick
'1Male'='Männlich'
'2Female'='Weiblich'
;
run;
title "just format statement";
proc sgplot data=sashelp.class noborder;
vbarbasic sex;
xaxis discreteorder=formatted
/* valuesformat=$sextick.*/
;
format sex $sex.;
run;
title;
title "with valuesformat";
proc sgplot data=sashelp.class noborder;
vbarbasic sex;
xaxis discreteorder=formatted
valuesformat=$sextick.
;
format sex $sex.;
run;
title;
Have a look at the following code sample. Two format are created, the first one is used for the ordering of the bars, the second one is used to label the tick marks. Note that the second format uses the formatted values as the input value. No truncation takes place.
proc format;
value $sex
'M'='1Male'
'F'='2Female'
;
value $sextick
'1Male'='Männlich'
'2Female'='Weiblich'
;
run;
title "just format statement";
proc sgplot data=sashelp.class noborder;
vbarbasic sex;
xaxis discreteorder=formatted
/* valuesformat=$sextick.*/
;
format sex $sex.;
run;
title;
title "with valuesformat";
proc sgplot data=sashelp.class noborder;
vbarbasic sex;
xaxis discreteorder=formatted
valuesformat=$sextick.
;
format sex $sex.;
run;
title;
Fun fact, the SGPLOT/XAXIS documentation does not mention about the tickvalueformat= option at all. The tickvalueformat= is only documented in GTL reference.
Bart
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: