BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Junyong
Pyrite | Level 9

I am drawing HISTOGRAMs using SGPLOT. I am seeing the HISTOGRAM and STYLEATTRS parts in the SAS manual, but couldn't find how to change the OUTLINE colors. This is the minimum sample code.

data have;
call streaminit(1);
do i=1 to 5000;
x=rand("t",3);
output;
end;
run;
ods listing gpath="!userprofile\desktop\";
ods graphics/reset;
ods results=off;
proc sgplot noautolegend;

HISTOGRAM X/NOFILL;

density x/type=normal(mu=0 sigma=1) lineattrs=(color=red);
xaxis display=(nolabel) values=(-6 to 6 by 1);
yaxis display=(nolabel);
run;
ods results=on;

The NOFILL option makes the bars white and their outlines black.

SGPlot.png

I tried to change this black using FILLENDCOLOR and STYLEATTRS DATACONTRASTCOLORS but didn't work. What should I do if I want to make the outline colors of the histogram bars blue?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

From the documentation for the STYLEATTRS statement:

At least one plot statement must specify the GROUP= option in order for the data attributes to take effect. This requirement applies to the DATACOLORS=, DATACONTRASTCOLORS=, DATALINEPATTERNS=, and DATASYMBOLS= options.

 

Since none of the shown code shows a Group= option then styleattrs statement is not having any affect.

So one way is to add a group variable that styleattrs can affect:

data have;
call streaminit(1);
do i=1 to 5000;
x=rand("t",3);
xgroup=1;
output;
end;
run;
proc sgplot data=have noautolegend;
styleattrs datacontrastcolors=(orange blue);
HISTOGRAM X/NOFILL group=xgroup;

density x/type=normal(mu=0 sigma=1) lineattrs=(color=red);
xaxis display=(nolabel) values=(-6 to 6 by 1);
yaxis display=(nolabel);
run;

or go to GTL.

View solution in original post

1 REPLY 1
ballardw
Super User

From the documentation for the STYLEATTRS statement:

At least one plot statement must specify the GROUP= option in order for the data attributes to take effect. This requirement applies to the DATACOLORS=, DATACONTRASTCOLORS=, DATALINEPATTERNS=, and DATASYMBOLS= options.

 

Since none of the shown code shows a Group= option then styleattrs statement is not having any affect.

So one way is to add a group variable that styleattrs can affect:

data have;
call streaminit(1);
do i=1 to 5000;
x=rand("t",3);
xgroup=1;
output;
end;
run;
proc sgplot data=have noautolegend;
styleattrs datacontrastcolors=(orange blue);
HISTOGRAM X/NOFILL group=xgroup;

density x/type=normal(mu=0 sigma=1) lineattrs=(color=red);
xaxis display=(nolabel) values=(-6 to 6 by 1);
yaxis display=(nolabel);
run;

or go to GTL.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 2362 views
  • 0 likes
  • 2 in conversation