I want both graphs to have the same color for the class variable. For the histogram, the coloring is set by
styleattrs DATACOLORS=(blue red )
But how do I set the same colors to differentiate between the classes in the vbar?
%let _input = sashelp.bweight;
%let class=black;
%let response=weight ;
proc sgplot data=&_input.;
title "Distribution &response.";
styleattrs DATACOLORS=(blue red );
histogram &response. / group=&class. transparency=0.5;
density &response. / group=&class. lineattrs=(pattern=solid);
xaxis display=(nolabel);
run;
proc sgplot data=&_input.;
styleattrs DATACOLORS=(blue red ) ;
title "Mean &response. per &class. ";
vbar &class. / response=&response. stat=Mean name='Bar' filltype= solid datalabel;
yaxis grid;
run;
Add the GROUP= Option to the VBAR Options to make the procedure alter between the specified datacolors
%let _input = sashelp.bweight;
%let class=black;
%let response=weight ;
proc sgplot data=&_input.;
title "Distribution &response.";
styleattrs DATACOLORS=(blue red);
histogram &response. / group=&class. transparency=0.5;
density &response. / group=&class. lineattrs=(pattern=solid);
xaxis display=(nolabel);
run;
proc sgplot data=&_input.;
styleattrs datacolors=(blue red) ;
title "Mean &response. per &class. ";
vbar &class. / group=&class. response=&response. stat=Mean name='Bar' filltype=solid datalabel;
yaxis grid;
run;
Edit: Also, you can add the transparency=0.5 to the VBAR option (as in the histogram options) to make the colors exactly the same.
Add the GROUP= Option to the VBAR Options to make the procedure alter between the specified datacolors
%let _input = sashelp.bweight;
%let class=black;
%let response=weight ;
proc sgplot data=&_input.;
title "Distribution &response.";
styleattrs DATACOLORS=(blue red);
histogram &response. / group=&class. transparency=0.5;
density &response. / group=&class. lineattrs=(pattern=solid);
xaxis display=(nolabel);
run;
proc sgplot data=&_input.;
styleattrs datacolors=(blue red) ;
title "Mean &response. per &class. ";
vbar &class. / group=&class. response=&response. stat=Mean name='Bar' filltype=solid datalabel;
yaxis grid;
run;
Edit: Also, you can add the transparency=0.5 to the VBAR option (as in the histogram options) to make the colors exactly the same.
Thank you, didnt realise I needed to specify groups= , thought that would be implicit.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.