BookmarkSubscribeRSS Feed
spidersgeorg
Calcite | Level 5

Hello, 

 

I am using proc sgpanel and have created the following histogram.graph.PNGusing the following code: 

 

title 'alcohol gm/d by sex - count';
proc sgpanel data=amd2prog_p noautolegend;
 panelby Sex;
 histogram alc_gm_d/ scale=count group=sex;
 density alc_gm_d;
run;

I was wondering if there is a way to change the colors of the groups? For example, to make sex=male green and sex=female pink or something?

 

Thanks!

2 REPLIES 2
ballardw
Super User

In increasing complexity:

1) use the Styleattrs statement to set graph properties.

   add Styleattrs datacolors=(pink green); to your graph.

  The first color will go with the first encountered group value. So Female would be before Male with the PanelBY, and Pink would associate with Female.

The fun part with this finding which attribute: Datacolors, Datacontrastcolors, Datafillpatterns, Datalinepatterns or Datasymbols need to be used for which element of the graph.

 

2) a DATTRMAP data set, discrete attribute map, which contains specific variable names to link values to the color, contrast color, line attribute, text color or attribute. The data set would be referenced on the Proc Sgpanel (or Sgplot) statement and the plot statements, such as your Histogram would include an ATTRID= option to indicate which values of the ID variable are used with that statement

 

3) Create a custom style using Proc Template and make that the active ODS style for the procedure by using it with the STYLE=option of an ODS destination statement.

sbxkoenk
SAS Super FREQ

Using dattrmap !

data myattrs;
length value $10 fillcolor $12;
show='AttrMap';
id="some_id";
value='F'; fillcolor="yellow"; output;
value='M'; fillcolor="purple"; output;
run;

title1 h=18pt ls=1.5 "ODS Graphics - Color Control";

proc sgpanel data=sashelp.class dattrmap=myattrs noautolegend
                                pad=(left=10pct right=10pct);
 panelby Sex;
 histogram height / scale=count group=sex attrid=some_id;
 density height;
run;
/* end of program */

Koen

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 707 views
  • 2 likes
  • 3 in conversation