This kind of code allows to list Male before Female in a proc means
proc sort data=sashelp.class out=class;
by sex;
run;
proc format;
value $sex (notsorted) 'M'='Male'
'F'='Female';
run;
proc means data=class;
class sex / preloadfmt order=data;
var height;
format sex $sex.;
run;
But as there is currently no preloadfmt
options with the xaxis statement, the following code has no effect on the result
ods graphics / width=15cm height=10cm;
proc sgplot data=class;
vbar sex / missing;
xaxis discreteorder=data;*formatted;
format sex $sex.;
run;
ods graphics off;
I know other ways to modify the order of the discrete values in the axis (vbarparm, xaxis values(), etc) but I would just like to know if it would work with vbar in a future SAS release.
Please try the below code
proc format;
value sexn (notsorted) 2='Male'
1='Female';
run;
data class;
set sashelp.class;
if sex='M' then sexn=2;
else if sex='F' then sexn=1;
run;
proc sgplot data=class;
vbar sexn / missing ;
xaxis discreteorder=formatted;
format sexn sexn.;
run;
oh ok, i thought you want female before male, if you want male before female then the code you posted is fine. I updated my code to generate the male before female
proc format;
value sexn (notsorted) 1='Male'
2='Female';
run;
data class;
set sashelp.class;
if sex='M' then sexn=1;
else if sex='F' then sexn=2;
run;
proc sgplot data=class;
vbar sexn / missing ;
xaxis discreteorder=formatted;
format sexn sexn.;
run;
Oh yeah, check this
proc sgplot data=class;
vbar sexn / missing ;
xaxis discreteorder=data;
format sexn sexn.;
run;
How about this one ?
proc sort data=sashelp.class out=class;
by sex;
run;
proc format;
value $sex 'M'=' Male'
'F'='Female';
run;
proc sgplot data=class;
vbar sex / missing;
format sex $sex.;
xaxis discreteorder=formatted ;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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: