BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASuserlot
Barite | Level 11

I am learning the Graphs , specially with SGPLOT.   I want to change the gridline colors for X and Y axis and change color of the background for the graph area. What options available? Please direct me to any references as well. Thank you for your time. I am also getting the note in the log ' Tick values have been thinned' . Is this because of the x axis tick value labels are long and not have enough space to fit? How  can I display all the dates in the data into the graph

SASuserlot_0-1659621448223.png

SASuserlot_1-1659621694380.png

 

** Data preparation **;
proc sort data=sashelp.stocks out=stocks;
by date;
where stock = "IBM" and "01DEC04"d <= date <= "01DEC05"d;
format date date9.;
run;

ODS html;
proc sgplot data=stocks;
	series x = date y = open / lineattrs = (color = red thickness = 1
	 pattern=solid);
	series x = date y = high / lineattrs = (color = green thickness = 1
	 pattern=solid);
	series x = date y = low / lineattrs = (color = purple thickness = 1
	 pattern=solid);
	series x = date y = close / lineattrs = (color = blue thickness = 1
	 pattern=solid);
	xaxis label = 'Date' values=("01DEC04"d to "01DEC05"d by month) grid;
	yaxis label = ' ' grid values = (70 to 100 by 2.00);
run;
ods _all_ close;
1 ACCEPTED SOLUTION

Accepted Solutions
Adriaan_Gouws
Obsidian | Level 7

Good day

 

Please include the below in your code.

proc sgplot data=stocks;
/*Using styleattrs, you can set some attributes for the chart*/
/*Color for outside chart area: backcolor*/
/*Color for inside chart area: wallcolor*/
styleattrs backcolor=blue wallcolor=azure;
series x = date y = open / lineattrs = (color = red thickness = 1
pattern=solid);
series x = date y = high / lineattrs = (color = green thickness = 1
pattern=solid);
series x = date y = low / lineattrs = (color = purple thickness = 1
pattern=solid);
series x = date y = close / lineattrs = (color = blue thickness = 1
pattern=solid);
xaxis label = 'Date' values=("01DEC04"d to "01DEC05"d by month) grid
/*Change the grid color here:*/
gridattrs=(color=purple);
yaxis label = ' ' grid values = (70 to 100 by 2.00)

/*Change the grid color here:*/
gridattrs=(color=red)
;
run;

View solution in original post

4 REPLIES 4
Adriaan_Gouws
Obsidian | Level 7

Good day

 

Please include the below in your code.

proc sgplot data=stocks;
/*Using styleattrs, you can set some attributes for the chart*/
/*Color for outside chart area: backcolor*/
/*Color for inside chart area: wallcolor*/
styleattrs backcolor=blue wallcolor=azure;
series x = date y = open / lineattrs = (color = red thickness = 1
pattern=solid);
series x = date y = high / lineattrs = (color = green thickness = 1
pattern=solid);
series x = date y = low / lineattrs = (color = purple thickness = 1
pattern=solid);
series x = date y = close / lineattrs = (color = blue thickness = 1
pattern=solid);
xaxis label = 'Date' values=("01DEC04"d to "01DEC05"d by month) grid
/*Change the grid color here:*/
gridattrs=(color=purple);
yaxis label = ' ' grid values = (70 to 100 by 2.00)

/*Change the grid color here:*/
gridattrs=(color=red)
;
run;
SASuserlot
Barite | Level 11

Thank you very much  for giving the solution to this query.

ballardw
Super User

First the tick mark issue: You requested 13 tick mark values with your Xaxis values list. If you look on the graph that only displays 7 you will see that there is not sufficient space for the text of 6 more ticks. The FITPOLICY option controls how SAS will attempt to fit your requested tic values on a graph. The default for linear axis such as date values is to THIN which means remove some.  You can use options such as FITPOLICY=Stagger, which would display the text at different levels and may allow all of the requested ticks to be present. You can use FITPOLICY=Rotate to angle the text (use VALUESROTATE= to provide rotation control) . There are others that can be used to combine rotate and stagger and such. Or display less text. If you format the date variable as MONYY5. the display will be month abbreviation and 2 digit year such as DEC04. Less text may allow all the ticks to fit. Another option is to increase the size of the graphic (ods graphics options) or reduce the font size on the XAXIS LABELATTRS=(Size=8pt) would set the text size to 8pt which again may allow more of the labels to fit.

 

Combinations of the above will get most reasonable number of axis labels and tick marks to appear.

 

GRIDATTRS set grid appearance options such as color for an axis. Add GRIDATTRS=(color=green) to an axis to have the associated grid lines appear in green.

A STYLEATTRS statement can set the background color.

Styleattrs backcolor=verylightblue;

for example will set the graph area to a light blue color.

 

SASuserlot
Barite | Level 11

Thank you so much for your input and time  @ballardw . You explanation worked for my requirement. For some reason I have to use the 'NOTIMESPLIT ' for 'FITPOLICY= rotate' to work. I accepted the @Adriaan_Gouws  as solution since it has the code ( it did not have the FITPOLICY details. Unfortunately I can not choose multiples as Answer. Again I really appreciate your time. I posting the full code incase it useful for any.

output:

SASuserlot_0-1659656563609.png

 

** Data preparation **;
proc sort data=sashelp.stocks out=stocks;
by date;
where stock = "IBM" and "01DEC04"d <= date <= "01DEC05"d;
format date date9.;
run;
ods html;
proc sgplot data=stocks;
/*Using styleattrs, you can set some attributes for the chart*/
/*Color for outside chart area: backcolor*/
/*Color for inside chart area: wallcolor*/
styleattrs backcolor= white  wallcolor=PapayaWhip;
series x = date y = open / lineattrs = (color = red thickness = 1
pattern=solid);
series x = date y = high / lineattrs = (color = green thickness = 1
pattern=solid);
series x = date y = low / lineattrs = (color = purple thickness = 1
pattern=solid)  ;
series x = date y = close / lineattrs = (color = blue thickness = 1
pattern=solid);
xaxis label = 'Date' values=("01DEC04"d to "01DEC05"d by month)  NOTIMESPLIT FITPOLICY= rotate grid
/*Change the grid color here:*/
gridattrs=(color=purple);
yaxis label = ' ' grid values = (70 to 100 by 2.00)

/*Change the grid color here:*/
gridattrs=(color=red)
;
run;
ods _all_ close;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 1294 views
  • 4 likes
  • 3 in conversation