Style Examples for ODS Graphics
/****************************************************************/
/* S A S S A M P L E L I B R A R Y */
/* */
/* NAME: ODSGRSTY */
/* TITLE: Style Examples for ODS Graphics */
/* PRODUCT: STAT */
/* SYSTEM: ALL */
/* KEYS: graphics, ods */
/* PROCS: */
/* DATA: */
/* */
/* SUPPORT: saswfk UPDATE: July 25, 2011 */
/* REF: ods graphics */
/* MISC: */
/* NOTES: This sample provides DATA step and PROC code */
/* from the chapter "Statistical Graphics Using ODS." It */
/* does not provide all of the ODS statements and style */
/* changes that are in the example. Rather, this sample */
/* provides code that can be run in one large batch to make */
/* all of the graphs in the example. In practice, you would */
/* not want to repeatedly open and close destinations as is */
/* done in the chapter. Note that you should not specify */
/* destination style changes without first closing a */
/* destination. Changing the style of the output without */
/* first closing the destination will not work as you might */
/* expect. Do not do the following: */
/* */
/* ODS HTML STYLE=STATISTICAL; */
/* . . . code . . . */
/* ODS HTML STYLE=DEFAULT; */
/* . . . code . . . */
/* ODS HTML STYLE=ANALYSIS; */
/* . . . code . . . */
/* */
/* Instead, do the following: */
/* */
/* ODS HTML STYLE=STATISTICAL FILE='file1.htm'; */
/* . . . code . . . */
/* ODS HTML CLOSE; */
/* ODS HTML STYLE=DEFAULT FILE='file2.htm'; */
/* . . . code . . . */
/* ODS HTML CLOSE; */
/* ODS HTML STYLE=ANALYSIS FILE='file3.htm'; */
/* . . . code . . . */
/* ODS HTML CLOSE; */
/* */
/* Note that some steps are commented out in this sample */
/* because they create large volumes of output. To run */
/* those steps, remove the comments. */
/****************************************************************/
proc template;
list styles;
/*
source Styles.Default;
source Styles.Statistical;
source Styles.Journal;
source Styles.RTF;
source Styles.HTMLBlue;
*/
run;
/*
proc template;
source styles.default;
run;
*/
proc format;
value vf 5 = 'GraphValueText';
run;
data x1;
array y[20] y0 - y19;
do x = 1 to 20; y[x] = x - 0.5; end;
do x = 0 to 10 by 5; output; end;
label y0 = 'GraphLabelText' x = 'GraphLabelText';
format x y0 vf.;
run;
%macro d;
%do i = 1 %to 12;
reg y=y%eval(19-&i) x=x / lineattrs=GraphData&i markerattrs=GraphData&i
curvelabel=" GraphData&i" curvelabelpos=max;
%end;
%mend;
%macro l(i, l);
reg y=y&i x=x / lineattrs=&l markerattrs=&l curvelabel=" &l"
curvelabelpos=max;
%mend;
*
ods listing style=default;
proc sgplot noautolegend data=x1;
title 'GraphTitleText';
%d
%l(19, GraphDataDefault)
%l( 6, GraphFit)
%l( 5, GraphFit2)
%l( 4, GraphPredictionLimits)
%l( 3, GraphConfidence)
%l( 2, GraphGridLines)
%l( 1, GraphOutlier)
%l( 0, GraphReference)
xaxis values=(0 5 10);
run;
data x2;
do y = 40 to 1 by -1;
group = 'Group' || put(41 - y, 2. -L);
do x = 0 to 10 by 5;
if x = 10 then do; z = 11; l = group; end;
else do; z = .; l = ' '; end;
output;
end;
end;
run;
proc sgplot data=x2;
title 'Colors, Markers, Lines Patterns for Groups';
series y=y x=x / group=group markers;
scatter y=y x=z / group=group markerchar=l;
run;
proc template;
%let m = circle square diamond asterisk plus triangle circlefilled
starfilled squarefilled diamondfilled trianglefilled;
%let ls = 1 4 8 5 14 26 15 20 41 42 2;
%macro makestyle;
%let l = %eval(%sysfunc(mod(&k,12))+1);
%let k = %eval(&k+1);
style GraphData&k from GraphData&l /
linestyle=%scan(&ls, &j) markersymbol="%scan(&m, &i)";
%mend;
define style styles.HTMLBlueL;
parent=styles.htmlbluecml;
style GraphFit2 from GraphFit2 / linestyle = 1;
%macro htmlbluel;
%let k = 0;
%do i = 1 %to 11; %do j = 1 %to 11; %makestyle %end; %end;
%mend;
%htmlbluel
end;
define style styles.HTMLBlueM;
parent=styles.htmlbluecml;
style GraphFit2 from GraphFit2 / linestyle = 1;
%macro htmlbluem;
%let k = 0;
%do j = 1 %to 11; %do i = 1 %to 11; %makestyle %end; %end;
%mend;
%htmlbluem
end;
%let m = circlefilled starfilled squarefilled diamondfilled trianglefilled;
define style styles.HTMLBlueFL;
parent=styles.htmlbluecml;
style GraphFit2 from GraphFit2 / linestyle = 1;
%macro htmlbluel;
%let k = 0;
%do i = 1 %to 5; %do j = 1 %to 11; %makestyle %end; %end;
%mend;
%htmlbluel
end;
define style styles.HTMLBlueFM;
parent=styles.htmlbluecml;
style GraphFit2 from GraphFit2 / linestyle = 1;
%macro htmlbluem;
%let k = 0;
%do j = 1 %to 11; %do i = 1 %to 5; %makestyle %end; %end;
%mend;
%htmlbluem
end;
run;
proc sgplot data=x2;
title 'Colors, Markers, Lines Patterns for Groups';
series y=y x=x / group=group markers;
scatter y=y x=z / group=group markerchar=l;
run;
ods graphics on;
*
ods listing style=statistical;
proc transreg data=sashelp.Gas ss2 plots=transformation lprefix=0;
model identity(nox) = class(Fuel / zero=none) * pbspline(EqRatio);
run;
%modstyle(parent=statistical, name=StatColor)
*
ods listing style=StatColor;
proc transreg data=sashelp.Gas ss2 plots=transformation lprefix=0;
model identity(nox) = class(Fuel / zero=none) * pbspline(EqRatio);
run;
data x;
do g = 1 to 12;
do x = 1 to 10;
y = 13 - g + sin(x * 0.1 * g);
output;
end;
end;
run;
%modstyle(name=markstyle, parent=statistical, type=CLM,
markers=star plus circle square diamond starfilled
circlefilled squarefilled diamondfilled)
*
ods listing style=markstyle;
proc sgplot;
title 'Modified Marker List';
loess y=y x=x / group=g;
run;
%modstyle(name=linestyle, parent=statistical, type=CLM,
linestyles=Solid LongDash MediumDash Dash ShortDash Dot ThinDot)
*
ods listing style=linestyle;
proc sgplot;
title 'Modified Line Style List';
loess y=y x=x / group=g;
run;
/*
proc template;
source styles.markstyle;
source styles.linestyle;
run;
*/
/*
proc template;
source Styles.HTMLBlue;
source Styles.Statistical;
source Styles.Default;
run;
*/
proc template;
define style Styles.NewStyle;
parent=Styles.Statistical;
replace GraphFonts /
'GraphDataFont' = ("<MTserif>, Times New Roman",7pt)
'GraphUnicodeFont' = ("<MTserif>, Times New Roman",9pt)
'GraphValueFont' = ("<MTserif>, Times New Roman",9pt)
'GraphLabel2Font' = ("<MTserif>, Times New Roman",10pt)
'GraphLabelFont' = ("<MTserif>, Times New Roman",10pt)
'GraphFootnoteFont' = ("<MTserif>, Times New Roman",10pt)
'GraphTitleFont' = ("<MTserif>, Times New Roman",11pt)
'GraphTitle1Font' = ("<MTserif>, Times New Roman",14pt)
'GraphAnnoFont' = ("<MTserif>, Times New Roman",10pt);
end;
run;
data stack;
input x1 x2 x3 y @@;
datalines;
80 27 89 42 80 27 88 37 75 25 90 37 62 24 87 28 62 22 87 18
62 23 87 18 62 24 93 19 62 24 93 20 58 23 87 15 58 18 80 14
58 18 89 14 58 17 88 13 58 18 82 11 58 19 93 12 50 18 89 8
50 18 86 7 50 19 72 8 50 19 79 8 50 20 80 9 56 20 82 15
70 20 91 15
;
*
ods listing style=HTMLBlue;
proc robustreg data=stack plots=qqplot;
ods select QQPlot;
model y = x1 x2 x3;
run;
/*
ods listing close;
ods listing style=NewStyle;
proc robustreg data=stack plots=qqplot;
ods select QQPlot;
model y = x1 x2 x3;
run;
*/
/*
proc template;
source styles.HTMLBlue;
run;
*/
/*
proc template;
source styles.statistical;
run;
*/
/*
proc template;
source Styles.HTMLBlue;
source Styles.Statistical;
source Styles.Default;
run;
*/
proc template;
define style Styles.NewStyle;
parent=Styles.Statistical;
replace GraphFonts /
'GraphDataFont' = ("<MTserif>, Times New Roman",7pt)
'GraphUnicodeFont' = ("<MTserif>, Times New Roman",9pt)
'GraphValueFont' = ("<MTserif>, Times New Roman",9pt)
'GraphLabel2Font' = ("<MTserif>, Times New Roman",10pt)
'GraphLabelFont' = ("<MTserif>, Times New Roman",10pt)
'GraphFootnoteFont' = ("<MTserif>, Times New Roman",10pt)
'GraphTitleFont' = ("<MTserif>, Times New Roman",11pt)
'GraphTitle1Font' = ("<MTserif>, Times New Roman",14pt)
'GraphAnnoFont' = ("<MTserif>, Times New Roman",10pt);
replace GraphReference / linethickness=4px;
end;
run;
/*
ods listing style=NewStyle;
ods graphics on;
proc robustreg data=stack plots=qqplot;
ods select QQPlot;
model y = x1 x2 x3;
run;
*/