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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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