Good morning,
I'm having a problem that the X axis color is not as defined in PNG output. As you can see in the attachments, the X axis color is grey in the SAS output which is the color I want, but in the PNG output it is still black. Could someone help me with it? Thanks.
Here is my code:
data anno;
drawspace = 'GraphPercent';
function = 'Rectangle';
cornerradius=0.1;
linestyleelement='GraphAxisLines';
TRANSPARENCY=0.5;
Border=NOborder;
retain x1 y1 50 height width 100 widthunit 'Percent';
run;
ods graphics on/reset IMAGENAME ="&sheet.."
IMAGEFMT =PNG
width=8in height=2in;
goptions device=png gsfname=graphout;
PROC SGPLOT DATA = T1&sheet. sganno=anno dattrmap=attrmap noborder;
Scatter Y=NAME X = MY2R/markerAttrs=(size=6mM) group=MY2 attrid=MY2 datalabel=MY2R DATALABELATTRS=(size=8.5pt Family=ArialNarrow weight=bold COLOR=White) DATALABELPOS=CENTER transparency=0.1;
XAXIS DISPLAY=(NOTICKS) TICKVALUEFORMAT=data VALUEATTRS=(color=grey) label=' ';
YAXIS DISPLAY=(NOTICKS noline) LABEL = ' ' labelattrs=(color=White) valueattrs=(size=12pt Family=Arial color=black) GRID gridattrs=(color=WhiteSmoke) MINORGRIDATTRS=(color=green pattern=longdash thickness=2);
keylegend 'Percent'/noborder;
title "&sheet.";
run;
As far as I know the color of an axis line can only be changed using a style.
Here is an example of creating your own style and change the color, I have used red for better visability.
/* add my own itemsore in front of the ods path */
ods path
(prepend) work.mytemplates (update)
;
/* show source of defualt style */
proc template;
source styles.default;
run;
/* build my own style, only changing the color */
proc template;
define style styles.greyLine;
parent=styles.htmlblue;
class GraphAxisLines /
contrastcolor = red
color = red
;
class GraphValueText /
color = red
;
end;
run;
ods html file="c:\temp\sample.html" gpath="c:\temp" style=styles.greyline;
proc sgplot data = sashelp.class tmplout="c:\temp\sgplot.sas" noborder;
scatter x=age y=height;
xaxis display=(noticks) tickvalueformat=data label=' ';
run;
ods html close;
Maybe you can also use the REFLINE statement to add additional lines, you can control the color of each reference line.
Try removing the GOPTIONS statement. Normally, GOPTIONs should not be used with the ODS Graphics system. Let me know if that makes a difference.
Thanks!
Dan
Thanks Dan, I removed the "goptions device=png gsfname=graphout;" but it is still did not work.
Do you want to control the color of xaxis line or the color of the xaxis thick mark values?
Hi Bruno, I want to control both of them and both color should be grey.
What ODS destinations do you have open? I cannot tell by your code.
What ODS destinations do you have open? I cannot tell by your code.
As far as I know the color of an axis line can only be changed using a style.
Here is an example of creating your own style and change the color, I have used red for better visability.
/* add my own itemsore in front of the ods path */
ods path
(prepend) work.mytemplates (update)
;
/* show source of defualt style */
proc template;
source styles.default;
run;
/* build my own style, only changing the color */
proc template;
define style styles.greyLine;
parent=styles.htmlblue;
class GraphAxisLines /
contrastcolor = red
color = red
;
class GraphValueText /
color = red
;
end;
run;
ods html file="c:\temp\sample.html" gpath="c:\temp" style=styles.greyline;
proc sgplot data = sashelp.class tmplout="c:\temp\sgplot.sas" noborder;
scatter x=age y=height;
xaxis display=(noticks) tickvalueformat=data label=' ';
run;
ods html close;
Maybe you can also use the REFLINE statement to add additional lines, you can control the color of each reference line.
Thanks Bruno, it works!
If you send output to a different ODS destination and do not specify the same style then you likely get different results as HTML, RTF and PDF destinations by default use different ODS STYLES.
Change the path information in the code below and examine the differences between the 4 output files:
ods rtf file="c:\path\demo.rtf" ; ods pdf file="c:\path\demo.pdf" ; PROC SGPLOT DATA = T1&sheet. sganno=anno dattrmap=attrmap noborder; Scatter Y=NAME X = MY2R/markerAttrs=(size=6mM) group=MY2 attrid=MY2 datalabel=MY2R DATALABELATTRS=(size=8.5pt Family=ArialNarrow weight=bold COLOR=White) DATALABELPOS=CENTER transparency=0.1; XAXIS DISPLAY=(NOTICKS) TICKVALUEFORMAT=data VALUEATTRS=(color=grey) label=' '; YAXIS DISPLAY=(NOTICKS noline) LABEL = ' ' labelattrs=(color=White) valueattrs=(size=12pt Family=Arial color=black) GRID gridattrs=(color=WhiteSmoke) MINORGRIDATTRS=(color=green pattern=longdash thickness=2); keylegend 'Percent'/noborder; title "&sheet."; run; ods pdf close; ods rtf close; ods rtf file="c:\path\demo2.rtf" style=meadow; ods pdf file="c:\path\demo2.pdf" style=meadow; PROC SGPLOT DATA = T1&sheet. sganno=anno dattrmap=attrmap noborder; Scatter Y=NAME X = MY2R/markerAttrs=(size=6mM) group=MY2 attrid=MY2 datalabel=MY2R DATALABELATTRS=(size=8.5pt Family=ArialNarrow weight=bold COLOR=White) DATALABELPOS=CENTER transparency=0.1; XAXIS DISPLAY=(NOTICKS) TICKVALUEFORMAT=data VALUEATTRS=(color=grey) label=' '; YAXIS DISPLAY=(NOTICKS noline) LABEL = ' ' labelattrs=(color=White) valueattrs=(size=12pt Family=Arial color=black) GRID gridattrs=(color=WhiteSmoke) MINORGRIDATTRS=(color=green pattern=longdash thickness=2); keylegend 'Percent'/noborder; title "&sheet."; run; ods pdf close; ods rtf close;
Hi Ballard,
Thanks for your help. The meadow style did not make grey color but it did change the X axis color.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.