Documentation Example 2 for Template Modification
/****************************************************************/
/* S A S S A M P L E L I B R A R Y */
/* */
/* NAME: TEMPLEX2 */
/* TITLE: Documentation Example 2 for Template Modification */
/* PRODUCT: STAT */
/* SYSTEM: ALL */
/* KEYS: graphics, ods */
/* PROCS: */
/* DATA: */
/* */
/* SUPPORT: saswfk UPDATE: July 25, 2011 */
/* REF: ods graphics */
/* MISC: */
/* NOTES: This sample provides the DATA step and PROC code */
/* from the chapter "ODS Graphics Template Modification." It */
/* does not provide most of the ODS statements and style */
/* changes that are in the chapter. Rather, this sample */
/* provides code that can be run in one large batch to make */
/* all of the graphs in the chapter. If destinations were */
/* repeatedly opened and closed, as in the chapter, then */
/* output would be lost and rewritten. 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; */
/* . . . code . . . */
/* ODS HTML CLOSE; */
/* ODS HTML STYLE=DEFAULT; */
/* . . . code . . . */
/* ODS HTML CLOSE; */
/* ODS HTML STYLE=ANALYSIS; */
/* . . . code . . . */
/* ODS HTML CLOSE; */
/* */
/* Note that several steps are commented out in this sample, */
/* because they create large volumes of output. To run those */
/* steps, remove the comments. */
/****************************************************************/
ods graphics on;
ods trace on;
proc reg data=sashelp.class;
model weight = height;
run;
proc reg data=sashelp.class;
ods output fitstatistics=fs ParameterEstimates=c;
model weight = height;
run;
data _null_;
set fs;
if _n_ = 1 then call symputx('R2' , put(nvalue2, 4.2) , 'G');
if _n_ = 2 then call symputx('mean', put(nvalue1, best6.), 'G');
run;
data _null_;
set c;
length s $ 200;
retain s ' ';
if _n_ = 1 then
s = trim(dependent) || ' = ' || /* dependent = */
put(estimate, best5. -L); /* intercept */
else if abs(estimate) > 1e-8 then do; /* skip zero coefficients */
s = trim(s) || ' ' || /* string so far */
scan('+ -', 1 + (estimate < 0), ' ') /* + (add) or - (subtract) */
|| ' ' ||
trim(put(abs(estimate), best5. -L)) /* abs(coefficient) */
|| ' ' || variable; /* variable name */
end; /* e for error added next */
call symputx('formula', trim(s) || ' + e', 'G');
run;
proc sgplot data=sashelp.class;
title 'Simple Linear Regression';
inset "&formula"
"R(*ESC*){sup '2'} = &r2"
"(*ESC*){unicode mu}(*ESC*){unicode hat} = &mean" / position=topleft;
reg y=weight x=height / clm cli;
run;
proc template;
source Stat.Reg.Graphics.Fit;
run;
proc template;
define statgraph Stat.Reg.Graphics.Fit;
notes "Fit Plot";
mvar formula;
dynamic _DEPLABEL _DEPNAME _MODELLABEL _SHOWSTATS _NSTATSCOLS _SHOWNObs
_SHOWTOTFREQ _SHOWNParm _SHOWEDF _SHOWMSE _SHOWRSquare _SHOWAdjRSq
_SHOWSSE _SHOWDepMean _SHOWCV _SHOWAIC _SHOWBIC _SHOWCP _SHOWGMSEP
_SHOWJP _SHOWPC _SHOWSBC _SHOWSP _NObs _NParm _EDF _MSE _RSquare
_AdjRSq _SSE _DepMean _CV _AIC _BIC _CP _GMSEP _JP _PC _SBC _SP
_PREDLIMITS _CONFLIMITS _XVAR _SHOWCLM _SHOWCLI _WEIGHT _SHORTXLABEL
_SHORTYLABEL _TITLE _TOTFreq;
BeginGraph;
entrytitle halign=left textattrs=GRAPHVALUETEXT _MODELLABEL
halign=center textattrs=GRAPHTITLETEXT _TITLE " for " _DEPNAME;
layout Overlay / yaxisopts=(label=_DEPLABEL shortlabel=_SHORTYLABEL)
xaxisopts=(shortlabel=_SHORTXLABEL);
if (_SHOWCLM=1)
BANDPLOT limitupper=UPPERCLMEAN limitlower=LOWERCLMEAN x=_XVAR /
fillattrs=GRAPHCONFIDENCE connectorder=axis name="Confidence"
LegendLabel=_CONFLIMITS;
endif;
layout gridded / autoalign=(topleft topright bottomleft
bottomright);
entry halign=left formula;
entry halign=left "R"{sup '2'} " = " eval(put(_rsquare, 4.2));
entry halign=left "(*ESC*){unicode mu}(*ESC*){unicode hat} = "
eval(put(_depmean, best6.))
/ textattrs=GraphValueText
(family=GraphUnicodeText:FontFamily);
endlayout;
if (_SHOWCLI=1)
if (_WEIGHT=1)
SCATTERPLOT y=PREDICTEDVALUE x=_XVAR / markerattrs=(size=0)
datatransparency=.6 yerrorupper=UPPERCL yerrorlower=LOWERCL
name="Prediction" LegendLabel=_PREDLIMITS;
else
BANDPLOT limitupper=UPPERCL limitlower=LOWERCL x=_XVAR /
display=(outline) outlineattrs=GRAPHPREDICTIONLIMITS
connectorder=axis name="Prediction"
LegendLabel=_PREDLIMITS;
endif;
endif;
SCATTERPLOT y=DEPVAR x=_XVAR / markerattrs=GRAPHDATADEFAULT primary=
true rolename=(_tip1=OBSERVATION _id1=ID1 _id2=ID2 _id3=ID3 _id4=
ID4 _id5=ID5) tip=(y x _tip1 _id1 _id2 _id3 _id4 _id5);
SERIESPLOT y=PREDICTEDVALUE x=_XVAR / lineattrs=GRAPHFIT
connectorder=xaxis name="Fit" LegendLabel="Fit";
if (_SHOWCLI=1 OR _SHOWCLM=1)
DISCRETELEGEND "Fit" "Confidence" "Prediction" / across=3 HALIGN=
CENTER VALIGN=BOTTOM;
endif;
endlayout;
EndGraph;
end;
run;
proc reg data=sashelp.class;
model weight = height;
run;
proc template;
delete Stat.Reg.Graphics.Fit / store=sasuser.templat;
run;
proc transreg data=sashelp.class ss2;
ods output fitstatistics=fs coef=c;
model identity(weight) = pspline(height);
run;
data _null_;
set fs;
if _n_ = 1 then call symputx('R2' , put(value2, 4.2) , 'G');
if _n_ = 2 then call symputx('mean', put(value1, best6.), 'G');
run;
data _null_;
set c end=eof;
length s $ 200 c $ 1;
retain s ' ';
if _n_ = 1 then
s = scan(dependent, 2, '()') || ' = ' || /* dependent = */
put(coefficient, best5. -L); /* intercept */
else if abs(coefficient) > 1e-8 then do; /* skip zero coefficients */
s = trim(s) || ' ' || /* string so far */
scan('+ -', 1 + (coefficient < 0), ' ') /* + (add) or - (subtract) */
|| ' ' ||
trim(put(abs(coefficient), best5. -L )) /* abs(coefficient) */
|| ' ' || scan(variable, 2, '._'); /* variable name */
c = scan(variable, 2, '_'); /* grab power */
if c ne '1' then /* skip power for linear */
s = trim(s) || /* string so far */
"(*ESC*){sup '" || c || "'}"; /* add superscript */
end; /* e for error added next */
if eof then call symputx('formula', trim(s) || ' + e', 'G');
run;
proc sgplot data=sashelp.class;
title 'Cubic Fit Function';
inset "&formula"
"R(*ESC*){sup '2'} = &r2"
"(*ESC*){unicode mu}(*ESC*){unicode hat} = &mean" / position=topleft;
reg y=weight x=height / degree=3 cli clm;
run;
%let l = halign=left;
proc template;
define statgraph class;
begingraph / designheight=550px designwidth=520px;
layout overlay / xaxisopts=(display=none) yaxisopts=(display=none);
layout gridded / columns=3 autoalign=(topleft);
entry &l textattrs=(weight=bold) 'Description';
entry &l textattrs=(weight=bold) 'Displayed';
entry &l textattrs=(weight=bold) "Unicode";
entry &l 'R Square';
entry &l 'R' {sup '2'};
entry &l "'R' {sup '2'}";
entry &l 'y hat sub i';
entry &l 'y' {unicode hat}{sub 'i'};
entry &l "'y' {unicode hat}{sub 'i'}";
entry &l 'less than or equal ';
entry &l 'a ' {unicode '2264'x} ' b';
entry &l "'a ' {unicode '2264'x} ' b'";
entry &l 'greater than or equal ';
entry &l 'b ' {unicode '2265'x} ' a';
entry &l "'b ' {unicode '2265'x} ' a'";
entry &l 'infinity';
entry &l {unicode '221e'x};
entry &l "{unicode '221e'x}";
entry &l 'almost equal';
entry &l 'a ' {unicode '2248'x} ' b';
entry &l "'a ' {unicode '2248'x} ' b'";
entry &l 'combining tilde';
entry &l 'El nin' {unicode tilde} 'o';
entry &l "'El nin' {unicode tilde} 'o'";
entry &l 'grave accent';
entry &l 'cre' {unicode '0300'x} 'me';
entry &l "'cre' {unicode '0300'x} 'me'";
entry &l 'circumflex, acute accent ';
entry &l 'bru' {unicode '0302'x} 'le' {unicode '0301'x} 'e';
entry &l "'bru' {unicode '0302'x} 'le' {unicode '0301'x} 'e'";
entry &l 'alpha';
entry &l {unicode alpha} ' ' {unicode alpha_u};
entry &l "{unicode alpha} ' ' {unicode alpha_u}";
entry &l 'beta';
entry &l {unicode beta} ' ' {unicode beta_u};
entry &l "{unicode beta} ' ' {unicode beta_u}";
entry &l 'gamma';
entry &l {unicode gamma} ' ' {unicode gamma_u};
entry &l "{unicode gamma} ' ' {unicode gamma_u}";
entry &l 'delta';
entry &l {unicode delta} ' ' {unicode delta_u};
entry &l "{unicode delta} ' ' {unicode delta_u}";
entry &l 'epsilon';
entry &l {unicode epsilon} ' ' {unicode epsilon_u};
entry &l "{unicode epsilon} ' ' {unicode epsilon_u}";
entry &l 'zeta';
entry &l {unicode zeta} ' ' {unicode zeta_u};
entry &l "{unicode zeta} ' ' {unicode zeta_u}";
entry &l 'eta';
entry &l {unicode eta} ' ' {unicode eta_u};
entry &l "{unicode eta} ' ' {unicode eta_u}";
entry &l 'theta';
entry &l {unicode theta} ' ' {unicode theta_u};
entry &l "{unicode theta} ' ' {unicode theta_u}";
entry &l 'iota';
entry &l {unicode iota} ' ' {unicode iota_u};
entry &l "{unicode iota} ' ' {unicode iota_u}";
entry &l 'kappa';
entry &l {unicode kappa} ' ' {unicode kappa_u};
entry &l "{unicode kappa} ' ' {unicode kappa_u}";
entry &l 'lambda';
entry &l {unicode lambda} ' ' {unicode lambda_u};
entry &l "{unicode lambda} ' ' {unicode lambda_u}";
entry &l 'mu';
entry &l {unicode mu} ' ' {unicode mu_u};
entry &l "{unicode mu} ' ' {unicode mu_u}";
entry &l 'nu';
entry &l {unicode nu} ' ' {unicode nu_u};
entry &l "{unicode nu} ' ' {unicode nu_u}";
entry &l 'xi';
entry &l {unicode xi} ' ' {unicode xi_u};
entry &l "{unicode xi} ' ' {unicode xi_u}";
entry &l 'omicron';
entry &l {unicode omicron} ' ' {unicode omicron_u};
entry &l "{unicode omicron} ' ' {unicode omicron_u}";
entry &l 'pi';
entry &l {unicode pi} ' ' {unicode pi_u};
entry &l "{unicode pi} ' ' {unicode pi_u}";
entry &l 'rho';
entry &l {unicode rho} ' ' {unicode rho_u};
entry &l "{unicode rho} ' ' {unicode rho_u}";
entry &l 'sigma';
entry &l {unicode sigma} ' ' {unicode sigma_u};
entry &l "{unicode sigma} ' ' {unicode sigma_u}";
entry &l 'tau';
entry &l {unicode tau} ' ' {unicode tau_u};
entry &l "{unicode tau} ' ' {unicode tau_u}";
entry &l 'upsilon';
entry &l {unicode upsilon} ' ' {unicode upsilon_u};
entry &l "{unicode upsilon} ' ' {unicode upsilon_u}";
entry &l 'phi';
entry &l {unicode phi} ' ' {unicode phi_u};
entry &l "{unicode phi} ' ' {unicode phi_u}";
entry &l 'chi';
entry &l {unicode chi} ' ' {unicode chi_u};
entry &l "{unicode chi} ' ' {unicode chi_u}";
entry &l 'psi';
entry &l {unicode psi} ' ' {unicode psi_u};
entry &l "{unicode psi} ' ' {unicode psi_u}";
entry &l 'omega';
entry &l {unicode omega} ' ' {unicode omega_u};
entry &l "{unicode omega} ' ' {unicode omega_u}";
endlayout;
scatterplot y=weight x=height / markerattrs=(size=0);
endlayout;
endgraph;
end;
run;
proc sgrender data=sashelp.class template=class;
run;
%macro m(u);
entry halign=left "(*ESC*){unicode &u.x} {unicode &u.x}" /
textattrs=GraphValueText (family=GraphUnicodeText:FontFamily);
%mend;
proc template;
define statgraph markers;
begingraph / designheight=510px designwidth=350px;
layout overlay / xaxisopts=(display=none) yaxisopts=(display=none);
layout gridded / columns=1 autoalign=(topright);
entry " ";
%m('2193') %m('002A') %m('25cb') %m('25cf')
%m('25c7') %m('2666') %m('003e') %m('0023')
%m('2336') %m('002b') %m('25a1') %m('25a0')
%m('2606') %m('2605') %m('22a4') %m('223c')
%m('25b3') %m('25b2') %m('222a') %m('0058')
%m('0059') %m('005a')
endlayout;
scatterplot x=x1 y=y / group=m;
scatterplot x=x2 y=y / markercharacter=m;
scatterplot x=x3 y=y / markerattrs=(size=0);
endlayout;
endgraph;
end;
run;
%modstyle(name=mark, parent=statistical, markers=
ArrowDown Asterisk Circle CircleFilled Diamond DiamondFilled GreaterThan
Hash IBeam Plus Square SquareFilled Star StarFilled Tack Tilde Triangle
TriangleFilled Union X Y Z, linestyles=1, colors=black)
data x;
retain x1 1 x2 2 x3 3;
length m $ 20;
input m @@;
y = -_n_;
datalines;
ArrowDown Asterisk Circle CircleFilled Diamond DiamondFilled GreaterThan
Hash IBeam Plus Square SquareFilled Star StarFilled Tack Tilde Triangle
TriangleFilled Union X Y Z
;
*
ods listing style=mark;
proc sgrender data=x template=markers;
run;
*
ods listing;