Hello,
I've created two graphs from my data, one an overlaid histogram (HISTOGRAM statement) and one a stacked histogram (SGPANEL statement). Here is my code:
proc sgplot data=Surveys;styleattrs datacolors=(blue CXFF00FF);
where gender~='';styleattrs backcolor=white wallcolor=white;
format gender $gender.;histogram Weeks / group=gender transparency=0.5;
xaxis label='Weeks' LABELATTRS=(size=14) VALUEATTRS=(size=13);
keylegend / title='Gender' TITLEATTRS=(size=16) valueattrs=(size=12);
yaxis LABELATTRS=(size=14) VALUEATTRS=(size=13) grid GRIDATTRS=(color=LIGGR);run;
proc sgpanel data=Surveys;
styleattrs datacolors=(blue CXFF00FF) datacontrastcolors=(blue CXFF00FF);
where gender~=''; styleattrs backcolor=white wallcolor=white;
format gender $gender.;panelby gender / rows=2 layout=rowlattice;
histogram Weeks;
COLAXIS label='Weeks' LABELATTRS=(size=14) VALUEATTRS=(size=13);
rowaxis LABELATTRS=(size=14) VALUEATTRS=(size=13) grid GRIDATTRS=(color=LIGGR);
keylegend / title='Gender' TITLEATTRS=(size=16) valueattrs=(size=12); run;
Here are the graphs that come out:
The overlaid histogram (first graph) comes out the way I need with regard to the colors of the bars for each group (blue for male and a purplish color, CXFF00FF, for females). However, I can't figure out how to color the SGPANEL(second graph) the same way, despite using "styleattrs datacolors=(blue CXFF00FF) datacontrastcolors=(blue CXFF00FF)
". I've Googled around and can't seem to find a solution. Can you help? Thanks.
You need to include the GROUP= option on the HISTOGRAM statement in PROC SGPANEL. To get exactly the same colors/transparency as in the first image, use
histogram Weeks / group=gender transparency=0.5;
You need to include the GROUP= option on the HISTOGRAM statement in PROC SGPANEL. To get exactly the same colors/transparency as in the first image, use
histogram Weeks / group=gender transparency=0.5;
/*Using GROUP= option*/
proc sgpanel data=sashelp.heart;
panelby sex / rows=2 layout=rowlattice;
histogram weight/group=sex;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.