PROC TEMPLATE features:
EDIT statement
Header attributes
JUST=
STYLE=
Table attributes
DOUBLE_SPACE=
OVERLINE=
UNDERLINE=
Other ODS features:
ODS HTML statement
ODS SELECT statement
Data set: STATEPOP
Note: This example uses filenames that might not be valid in all operating environments. To successfully run the example in your operating environment, you might need to change the file specifications. See Appendix 3, 'ODS HTML Statements for Running Examples in Different Operating Environments,' on page 649.
This example customizes the table definition for the Moments output object from PROC UNIVARIATE. The first program uses the table definition that SAS supplies to generate both Listing output and HTML output of the Moments object.
The second program
creates and edits a copy of the default table definition.
edits a header within the table definition.
sets column attributes to enhance the appearance of both the HTML and the Listing output.
Note: This example uses filenames that might not be valid in all operating environments. To successfully run the example in your operating environment, you might need to change the file specifications. See Appendix 3, 'ODS HTML Statements for Running Examples in Different Operating Environments,' on page 649.
Set the SAS system options. The OPTIONS statement controls several aspects of the Listing output. None of these options affects the HTML output.
options nodate pageno=1 pagesize=60 linesize=72;
Create the HTML output and specify the name of the HTML file. The ODS HTML statement opens the HTML destination and creates HTML output. It sends all output objects to the external file defaultmoments-body.htm in the current directory. Some browsers require an extension of .htm or .html on the filename.
ods html body='defaultmoments-body.htm';
Select the output objects for the report. The ODS SELECT statement sends one output object, Moments , to the open ODS destinations. Both the Listing and the HTML destinations are open . (To learn the names of the output objects, run the procedure with the ODS TRACE ON statement in effect. See 'Example' on page 200.)
ods select moments;
Compute the descriptive statistics for one variable. PROC UNIVARIATE computes the univariate statistics for one variable, CityPop_90. It uses the default table definition, base.univariate.moments from the template store sashelp.tmplmst .
proc univariate data=statepop mu0=3.5; var citypop_90; title 'Default Moments Table'; run;
Stop the creation of the HTML output. The ODS HTML statement closes the HTML destination and all the files that are associated with it. You must close the destination before you can view the output with a browser.
ods html close;
Default Moments Table 1 The UNIVARIATE Procedure Variable: CityPop_90 (1990 metropolitan pop in millions) Moments N 51 Sum Weights 51 Mean 3.87701961 Sum Observations 197.728 Std Deviation 5.16465302 Variance 26.6736408 Skewness 2.87109259 Kurtosis 10.537867 Uncorrected SS 2100.27737 Corrected SS 1333.68204 Coeff Variation 133.21194 Std Error Mean 0.72319608
Specify the search path in order to locate the table definition. The ODS PATH statement specifies which locations to search for definitions that were created by PROC TEMPLATE, as well as the order in which to search for them. The statement is included to ensure that the example works correctly. However, if you have not changed the path, you do not need to include this statement because it specifies the default path.
ods path sasuser.templat(update) sashelp.tmplmst(read);
Create a modified table definition base.univariate.moments . The EDIT statement looks in the available template stores for a table definition called base.univariate.moments .By default, it first looks in SASUSER.TEMPLAT, but it finds nothing. Next , it looks in SASHELP.TMPLMST, which contains the table definitions that SAS provides. Because the EDIT statement can read this definition, this is the one that it uses. The program does not specify a destination for the edited definition, so PROC TEMPLATE writes to the first template store in the path that it can write to, which is SASUSER.TEMPLAT. Therefore, it creates a table definition of the same name as the original one in SASUSER.TEMPLAT. (See 'ODS PATH Statement' on page 149).
(To learn the name of the table definition that a procedure uses, run the procedure with the ODS TRACE ON statement in effect. See 'Example' on page 200).
proc template; edit base.univariate.moments;
Specify changes to the Moments output object. These three table attributes affect the presentation of the Moments output object in the Listing output. They have no effect on its presentation in the HTML output. DOUBLE_SPACE= double spaces between the rows of the output object. OVERLINE= and UNDERLINE= draw a continuous line before the first row of the table and after the last row of the table.
double_space=on; underline=on; overline=on;
Modify a table element. This EDIT statement edits the table element head within the table definition.
edit head;
Modify the appearance of the header. The STYLE= attribute alters the style element that produces the head table element. The style element header is defined in the default style definition, styles.default . Many procedures, including PROC UNIVARIATE, use this style element to produce headers for tables and columns . (For information on viewing a style definition, see
'What Style Definitions Are Shipped with SAS Software?' on page 30.) In this case, the STYLE= attribute specifies green for the foreground color and italic for the font style. All other attributes that are included in header remain in effect. The STYLE= attribute affects only the HTML output.
style=header{foreground=green font_style=italic};
Left justify the header text. The JUST= attribute left-justifies the text of the header in both the Listing and the HTML output.
just=left;
Stop the editing of the table element and the table definition. The first END statement ends the editing of the table element head . The second END statement ends the editing of the table base.univariate.moments .
end; end; run;
Create the HTML output and specify the name of the HTML file. The ODS HTML statement opens the HTML destination and creates HTML output. It sends all output objects to the external file custommoments-body.htm in the current directory. Some browsers require an extension of .htm or .html on the filename.
ods html body='custommoments-body.htm';
Select the output objects for the report. The ODS SELECT statement sends one output object, Moments , to the open ODS destinations. Both the Listing and the HTML destinations are open. (To learn the names of the output objects, run the procedure with the ODS TRACE ON statement in effect. See 'Example' on page 200.)
ods select moments;
Compute the descriptive statistics for one variable. PROC UNIVARIATE computes the univariate statistics for one variable, CityPop_90. This is the same PROC UNIVARIATE step that was used in 'Program 1: Using the Default Table Definition that SAS Provides' on page 516. The actual results of the procedure step are the same in this case, but they are presented differently because the procedure uses the edited table definition. It does so because when it looks for base.univariate.moments , it looks in the first template store in the path, SASUSER.TEMPLAT. If you wanted to use the table definition that is supplied by SAS, you would have to change the path with the ODS PATH statement (see 'ODS PATH Statement' on page 149).
proc univariate data=statepop mu0=3.5; var citypop_90; title 'Custom Moments Table'; run;
Stop the creation of the HTML output. The ODS HTML statement closes the HTML destination and all the files that are associated with it. You must close the destination before you can view the output with a browser.
ods html close;
Custom Moments Table 1 The UNIVARIATE Procedure Variable: CityPop_90 (1990 metropolitan pop in millions) Moments ----------------------------------------------------------------- N 51 Sum Weights 51 Mean 3.87701961 Sum Observations 197.728 Std Deviation 5.16465302 Variance 26.6736408 Skewness 2.87109259 Kurtosis 10.537867 Uncorrected SS 2100.27737 Corrected SS 1333.68204 Coeff Variation 133.21194 Std Error Mean 0.72319608 -----------------------------------------------------------------
PROC TEMPLATE features:
EDIT statement
COLUMN statement
DEFINE statement
STYLE= attribute
NOTES statement
DYNAMIC statement
Other ODS features:
ODS PATH statement
ODS HTML statement
ODS HTML CLOSE statement
This example compares the use of an EDIT statement with a DEFINE TABLE statement for the same table definition. The first program uses the EDIT statement to change the Base.Summary table definition. The foreground color of the NOBS column is changed to green. The other definitions and attributes of the Base.Summary table definition remain the same. The second program uses the DEFINE TABLE statement to define a new table using the same name, Base.Summary . The NOBS column is the only column defined in the new table definition. When the PROC SUMMARY step executes, only the NOBS column is printed. The only style attribute that is used to format the column is the foreground=green attribute.
Edit the existing table definition Base.Summary . The ODS PATH statement specifies which item store to search first for the table definition. The EDIT statement edits the table definition Base.Summary . The modified table definition Base.Summary is written to the WORK.TEMPLAT item store.
Note: This example uses filenames that might not be valid in all operating environments. To successfully run the example in your operating environment, you might need to change the file specifications. See Appendix 3, 'ODS HTML Statements for Running Examples in Different Operating Environments,' on page 649.
ods path work.templat (update) sashelp.tmplmst (read); proc template; edit Base.Summary; edit nobs; style={foreground=green}; end; end; run; ods html file="temp.html"; proc summary data=sashelp.class print; class age; run; ods html close;
The column labeled AGE remains in the output because AGE is defined as a dynamic variable which is passed to the original Base.Summary table definition and AGE is specified as the CLASS variable. The attributes of the NOBS column are modified in the EDIT statement where the NOBS column is defined.
The modified Base.Summary table definition changes the foreground color of the NOBS column to green. The vertical alignment and heading of the NOBS column, and the other table attributes, are retained from the default table definition and stay the same. To view the Base.Summary table definition created by Program 1, follow these steps.
Submit the following command in the command bar:
odstemplates
Double-click the item store WORK.TEMPLAT .
Double-click the item store Base .
Right-click the table definition Summary and select Open . The table definition Base.Summary is displayed in the Template Browser window.
proc template; define table Base.Summary / store = SASUSER.TEMPLAT; notes "Summary table for MEANS and SUMMARY"; dynamic one_var one_var_label one_var_name clmpct; column class nobs id type ways (varname) (label) (min) (max) (range) (n) (nmiss) (sumwgt) (sum) (mean) (uss) (css) (var) (stddev) (cv) (stderr ) (t) (probt) (lclm) (uclm) (skew) (kurt) (median) (mode) (q1) (q3) ( qrange) (p1) (p5) (p10) (p25) (p50) (p75) (p90) (p95) (p99); header h; define p99; header = "99th Pctl"; generic; end; define p95; header = "95th Pctl"; generic; end; define p90; header = "90th Pctl"; generic; end; define p75; header = "75th Pctl"; generic; end; define p50; header = "50th Pctl"; generic; end; define p25; header = "25th Pctl"; generic; end; define p10; header = "10th Pctl"; generic; end; define p5; header = "5th Ptcl"; generic; end; define p1; header = "1st Pctl"; generic; end; define qrange; header = "Quartile Range"; generic; end; define q3; header = "Upper Quartile"; generic; end; define q1; header = "Lower Quartile"; generic; end; define mode; header = "Mode"; generic; end; define median; header = "Median"; generic; end; define kurt; header = "Kurtosis"; generic; end; define skew; header = "Skewness"; generic; end; define uclm; define header huclm; text "Upper " clmpct BEST8. %nrstr("%%/CL for Mean"); split = "/"; end; header = huclm; generic; end; define lclm; define header hlclm; text "Lower " clmpct BEST8. %nrstr("%%/CL for Mean"); split = "/"; end; header = hlclm; generic; end; define probt; parent = Common.ParameterEstimates.Probt; generic; end; define t; parent = Common.ParameterEstimates.tValue; generic; end; define stderr; header = "Std Error"; parent = Common.ParameterEstimates.StdErr; generic; end; define cv; header = "Coeff of Variation"; generic; end; define stddev; header = "Std Dev"; generic; end; define var; header = "Variance"; generic; end; define css; define header hcss; text2 "CSS"; text "Corrected SS"; end; header = hcss; generic; end; define uss; define header huss; text2 "USS"; text "Uncorrected SS"; end; header = huss; generic; end; define mean; header = "Mean"; generic; end; define sum; header = "Sum"; generic; end; define sumwgt; header = "Sum Wgts"; generic; end; define nmiss; header = "N Miss"; generic; end; define n; header = "N"; generic; end; define range; header = "Range"; generic; end; define max; define header hmax; text2 "Max"; text "Maximum"; end; header = hmax; generic; end; define min; define header hmin; text2 "Min"; text "Minimum"; end; header = hmin; generic; end; define label; header = "Label"; id; generic; end; define varname; header = "Variable"; id; generic; end; define ways; header = "Ways"; vjust = T; id; end; define type; header = "Type"; vjust = T; id; end; define id; vjust = T; id; generic; end; define nobs; header = "N Obs"; vjust = T; style = { foreground = green }; id; end; define class; vjust = T; id; generic; blank_internal_dups; end; define h; text "Analysis Variable : " one_var_name " " one_var_label; space = 1; just = C; print = one_var; spill_margin; end; required_space = 5; underline; overline; byline; use_format_defaults; double_space; split_stack; use_name; order_data; classlevels; end; run;
Define the table Base.Summary . The ODS PATH statement specifies which item store to search first for the table definition. The DEFINE TABLE statement creates a new table definition Base.Summary . The new table definition Base.Summary is written to the WORK.TEMPLAT item store.
ods path work.templat (update) sashelp.tmplmst (read); proc template; define table Base.Summary; notes "Summary table for MEANS and SUMMARY"; dynamic clmpct one_var_name one_var_label one_var; column class nobs id type ways (varname) (label) (min) (max) (range) (n ) (nmiss) (sumwgt) (sum) (mean) (uss) (css) (var) (stddev) (cv) ( stderr) (t) (probt) (lclm) (uclm) (skew) (kurt) (median) (mode) (q1) (q3) (qrange) (p1) (p5) (p10) (p25) (p50) (p75) (p90) (p95) (p99); define nobs; style={foreground=green}; end; end; run; ods html file="temp.html"; proc summary data=sashelp.class print; class age; run; ods html close;
The column labeled AGE is missing because it was not defined in the new table definition Base.Summary . The new table definition only defined the NOBS column with a green foreground and no column headings.
The Base.Summary table definition defines the foreground color of the NOBS column to green. Because the vertical alignment and heading of the NOBS column, and the other table attributes, are not defined, they are no longer part of the Base.Summary table definition. To view the table definition Base.Summary created by Program 2, follow these steps.
Submit the following command: odstemplates
Double-click the item store WORK.TEMPLAT .
Double-click the item store Base .
Right-click the table definition Summary and select Open . The table definition Base.Summary is displayed in the Template Browser window.
proc template; define table Base.Summary / store = WORK.TEMPLAT; notes "Summary table for MEANS and SUMMARY"; dynamic clmpct one_var_name one_var_label one_var; column class nobs id type ways (varname) (label) (min) (max) (range) (n)(nmiss) (sumwgt) (sum) (mean) (uss) (css) (var) (stddev) (cv) (stderr) (t) (probt) (lclm) (uclm) (skew) (kurt) (median) (mode) (q1) (q3) (qrange) (p1) (p5) (p10) (p25) (p50) (p75) (p90) (p95) (p99); define nobs; style = { foreground = green }; end; end; run;
PROC TEMPLATE features:
Table attributes:
DOUBLE_SPACE=
OVERLINE=
UNDERLINE=
DEFINE TABLE statement:
COLUMN statement
DEFINE statement (for columns)
GENERIC= attribute
HEADER= attribute
ID= attribute
STYLE= attribute
VJUST= attribute
DEFINE statement (for headers)
TEXT statement
STYLE= attribute
SPACE= attribute
DEFINE FOOTER statement
HEADER statement
MVAR statement
Other ODS features:
ODS HTML statement
FILE statement with ODS= option
PUT statement with _ODS_ argument
This example creates a custom table definition for an output data set that PROC MEANS produces.
Note: This example uses filenames that might not be valid in all operating environments. To successfully run the example in your operating environment, you might need to change the file specifications. See Appendix 3, 'ODS HTML Statements for Running Examples in Different Operating Environments,' on page 649.
Set the SAS system options. The OPTIONS statement controls several aspects of the Listing output. None of these options affects the HTML output.
options nodate pageno=1 pagesize=60 linesize=72;
Create formats for the variables Year and School . PROC FORMAT creates formats for Year and School.
proc format; value yrFmt . = " All"; value $schFmt ' ' = "All "; run;
The data set Charity contains information about students' volunteer work for charity. The variables give the name of the school, the year of the fundraiser, the first name of each student, the amount of money that each student raised, and the number of hours that each student volunteered. The RETA IN statement and two sum statements compute the minimum and maximum values of Year . The CALL SYMPUT statements store these values in the macro variables FIRST_YEAR and LAST_YEAR. A DATA step creates this data set.
data Charity; input School $ 1-7 Year 9-12 Name $ 14-20 moneyRaised 22-26 hoursVolunteered 28-29; format moneyRaised dollar8.2; format hoursVolunteered f3.0; format Year yrFmt.; format School schFmt.; label School = "Schools"; label Year = "Years"; retain yearmin yearmax; yearmin=min(yearmin,year); yearmax=max(yearmax,year); call symput('first_year',put(yearmin,4.)); call symput('last_year',put(yearmax,4.)); datalines; Monroe 1992 Allison 31.65 19 Monroe 1992 Barry 23.76 16 Monroe 1992 Candace 21.11 5 Monroe 1992 Danny 6.89 23 Monroe 1992 Edward 53.76 31 Monroe 1992 Fiona 48.55 13 Monroe 1992 Gert 24.00 16 Monroe 1992 Harold 27.55 17 Monroe 1992 Ima 15.98 9 Monroe 1992 Jack 20.00 23 Monroe 1992 Katie 22.11 2 Monroe 1992 Lisa 18.34 17 Monroe 1992 Tonya 55.16 40 Monroe 1992 Max 26.77 34 Monroe 1992 Ned 28.43 22 Monroe 1992 Opal 32.66 14 Monroe 1993 Patsy 18.33 18 Monroe 1993 Quentin 16.89 15 Monroe 1993 Randall 12.98 17 Monroe 1993 Sam 15.88 5 Monroe 1993 Tyra 21.88 23 Monroe 1993 Myrtle 47.33 26 Monroe 1993 Frank 41.11 22 Monroe 1993 Cameron 65.44 14 Monroe 1993 Vern 17.89 11 Monroe 1993 Wendell 23.00 10 Monroe 1993 Bob 26.88 6 Monroe 1993 Leah 28.99 23 Monroe 1994 Becky 30.33 26 Monroe 1994 Sally 35.75 27 Monroe 1994 Edgar 27.11 12 Monroe 1994 Dawson 17.24 16 Monroe 1994 Lou 5.12 16 Monroe 1994 Damien 18.74 17 Monroe 1994 Mona 27.43 7 Monroe 1994 Della 56.78 15 Monroe 1994 Monique 29.88 19 Monroe 1994 Carl 31.12 25 Monroe 1994 Reba 35.16 22 Monroe 1994 Dax 27.65 23 Monroe 1994 Gary 23.11 15 Monroe 1994 Suzie 26.65 11 Monroe 1994 Benito 47.44 18 Monroe 1994 Thomas 21.99 23 Monroe 1994 Annie 24.99 27 Monroe 1994 Paul 27.98 22 Monroe 1994 Alex 24.00 16 Monroe 1994 Lauren 15.00 17 Monroe 1994 Julia 12.98 15 Monroe 1994 Keith 11.89 19 Monroe 1994 Jackie 26.88 22 Monroe 1994 Pablo 13.98 28 Monroe 1994 L.T. 56.87 33 Monroe 1994 Willard 78.65 24 Monroe 1994 Kathy 32.88 11 Monroe 1994 Abby 35.88 10 Kennedy 1992 Arturo 34.98 14 Kennedy 1992 Grace 27.55 25 Kennedy 1992 Winston 23.88 22 Kennedy 1992 Vince 12.88 21 Kennedy 1992 Claude 15.62 5 Kennedy 1992 Mary 28.99 34 Kennedy 1992 Abner 25.89 22 Kennedy 1992 Jay 35.89 35 Kennedy 1992 Alicia 28.77 26 Kennedy 1992 Freddy 29.00 27 Kennedy 1992 Eloise 31.67 25 Kennedy 1992 Jenny 43.89 22 Kennedy 1992 Thelma 52.63 21 Kennedy 1992 Tina 19.67 21 Kennedy 1992 Eric 24.89 12 Kennedy 1993 Bubba 37.88 12 Kennedy 1993 G.L. 25.89 21 Kennedy 1993 Bert 28.89 21 Kennedy 1993 Clay 26.44 21 Kennedy 1993 Leeann 27.17 17 Kennedy 1993 Georgia 38.90 11 Kennedy 1993 Bill 42.23 25 Kennedy 1993 Holly 18.67 27 Kennedy 1993 Benny 19.09 25 Kennedy 1993 Cammie 28.77 28 Kennedy 1993 Amy 27.08 31 Kennedy 1993 Doris 22.22 24 Kennedy 1993 Robbie 19.80 24 Kennedy 1993 Ted 27.07 25 Kennedy 1993 Sarah 24.44 12 Kennedy 1993 Megan 28.89 11 Kennedy 1993 Jeff 31.11 12 Kennedy 1993 Taz 30.55 11 Kennedy 1993 George 27.56 11 Kennedy 1993 Heather 38.67 15 Kennedy 1994 Nancy 29.90 26 Kennedy 1994 Rusty 30.55 28 Kennedy 1994 Mimi 37.67 22 Kennedy 1994 J.C. 23.33 27 Kennedy 1994 Clark 27.90 25 Kennedy 1994 Rudy 27.78 23 Kennedy 1994 Samuel 34.44 18 Kennedy 1994 Forrest 28.89 26 Kennedy 1994 Luther 72.22 24 Kennedy 1994 Trey 6.78 18 Kennedy 1994 Albert 23.33 19 Kennedy 1994 Che-Min 26.66 33 Kennedy 1994 Preston 32.22 23 Kennedy 1994 Larry 40.00 26 Kennedy 1994 Anton 35.99 28 Kennedy 1994 Sid 27.45 25 Kennedy 1994 Will 28.88 21 Kennedy 1994 Morty 34.44 25 ;
Compute the descriptive statistics, and specify the options and subgroups for analysis. This PROC MEANS step analyzes the data for the one-way combination of the class variables and across all observations. It creates an output data set that includes variables for the total and average amount of money raised. The data set also includes new variables for the top three amounts of money raised, the names of the three students who raised the money, the years when the students raised the money, and the schools that the students attended.
proc means data=Charity descendTypes charType noprint; class School Year; var moneyRaised; types () School year; output out=top3list sum= mean= idgroup ( max(moneyRaised) out[3](moneyRaised name school year)= ) / autoname; run;
Print the report. This PROC PRINT step generates traditional Listing output of the output data set that PROC MEANS created.
proc print data=top3list nobs; title 'Simple PROC PRINT of the Output Data Set'; run;
Simple PROC PRINT of the Output Data Set 1 money money Raised_ Raised_ money money money School Year _TYPE_ _FREQ_ Sum Mean Raised_1 Raised_2 Raised_3 Kennedy All 10 53 75.95 .73 .22 .63 .89 Monroe All 10 56 16.80 .87 .65 .44 .87 All 1992 01 31 2.92 .80 .16 .76 .63 All 1993 01 32 7.92 .37 .44 .33 .23 All 1994 01 46 91.91 .26 .65 .22 .87 All All 00 109 92.75 .29 .65 .22 .44 Name_1 Name_2 Name_3 School_1 School_2 School_3 Year_1 Year_2 Year_3 Luther Thelma Jenny Kennedy Kennedy Kennedy 1994 1992 1992 Willard Cameron L.T. Monroe Monroe Monroe 1994 1993 1994 Tonya Edward Thelma Monroe Monroe Kennedy 1992 1992 1992 Cameron Myrtle Bill Monroe Monroe Kennedy 1993 1993 1993 Willard Luther L.T. Monroe Kennedy Monroe 1994 1994 1994 Willard Luther Cameron Monroe Kennedy Monroe 1994 1994 1993
Set the SAS system options. The OPTIONS statement controls several aspects of the Listing output. None of these options affects the HTML output.
options nodate pageno=1 pagesize=60 linesize=72;
Create the HTML output and specify the name of the HTML file. The ODS HTML statement opens the HTML destination and creates HTML output. It sends all output objects to the external file topn-body.htm in the current directory. Some browsers require an extension of .htm or .html on the filename.
ods html body='topn-body.htm';
Create the table definition means.topn The DEFINE statement creates the table definition means.topn in the first template store in the path for which you have write access. By default, this template store is SASUSER.TEMPLAT.
proc template; define table means.topn;
Specify the symbols that reference three macro variables. The MVAR statement defines three symbols that reference macro variables. ODS will use the values of these variables as strings. References to the macro variables are resolved when ODS binds the definition and the data component to produce an output object. FIRST_YEAR and LAST_YEAR will contain the values of the first and last years for which there are data. Their values are assigned by the SYMPUT statements in the DATA step. SYSDATE9 is an automatic macro variable whose value is always available.
mvar first_year last_year sysdate9;
Specify the column names and the order in which they appear in the report. The COLUMN statement declares these variables as columns in the table and specifies their order in the table. If a column name appears in parentheses, then PROC TEMPLATE stacks the values of all variables that use that column definition one below the other in the output object. Variables are assigned a column definition in the DATA step that appears later in the program.
column class sum mean (raised) (name) (school) (year);
Specify three customized changes to the table definition. These three table attributes affect the presentation of the output object in the Listing output. They have no effect on its presentation in the HTML output. DOUBLE_SPACE= double spaces the rows of the output object. OVERLINE= and UNDERLINE= draw a continuous line before the first row of the table and after the last row of the table.
double_space=on; overline=on; underline=on;
Specify the two table headers and the order in which they appear in the report. The HEADER statement declares table_header_1 and table_header_2 as headers in the table and specifies the order in which the headers appear in the output object.
header table_header_1 table_header_2;
Create the table element table_header_1 . The DEFINE statement and its substatement and attribute define table_header_1 . The TEXT statement specifies the text of the header. The STYLE= attribute alters the style element that displays the table header. The style element header is defined in the default style definition, styles.default . (For information on viewing a style definition, see
'What Style Definitions Are Shipped with SAS Software?' on page 30.) In this case, the STYLE= attribute specifies a large font size . All other attributes that are included in header remain in effect. This attribute affects only the HTML output.
The END statement ends the header definition.
define table_header_1; text "Top Three Fund Raisers"; style=header{font_size=6}; end;
Create the table element table_header_2 . The DEFINE statement and its substatement and attribute define table_header_2 . The TEXT statement uses text and the macro variables FIRST_YEAR and LAST_YEAR to specify the contents of the header. When ODS binds the data component to the table definition (in the DATA step that follows ), it will resolve the values of the macro variables FIRST_YEAR and LAST_YEAR. The table definition itself contains references to the macro variables.
The SPACE= attribute inserts a blank line after the header (in the Listing output only).
The END statement ends the header definition.
define table_header_2; text "from " first_year " to " last_year; space=1; end;
Create the table element table_footer . The DEFINE statement and its substatement and attribute define table_footer . The FOOTER argument declares table_footer as a footer. (Compare this approach with the creation of the headers. You could use a FOOTER statement instead of the FOOTER argument in the DEFINE statement.)
The TEXT statement specifies the text of the footer. When ODS binds the data component to the table definition (in the DATA step that follows), it will resolve the value of the macro variable SYSDATE9. The table definition itself contains a reference to the macro variable. The SPLIT= attribute specifies the asterisk as the split character. This prevents the header from splitting at the open parenthesis. If no split character is specified, then ODS interprets the nonalphabetic, leading character as the split character (see the discussion of text-specification(s) in 'TEXT Statement' on page 409.) Alternatively, you can place a space character before the open parenthesis.
The STYLE= attribute alters the style element that displays the table footer. The style element header is defined in the default style definition, styles.default . (For information on viewing a style definition, see
'Viewing the Contents of a Style Definition' on page 319.) In this case, the STYLE= attribute specifies a small font size. All other attributes that are included in footer remain in effect. This attribute affects only the HTML output.
The END statement ends the footer definition.
define footer table_footer; text "(report generated on " sysdate9 ")"; split="*"; style=header{font_size=2}; end;
Create the column class . The DEFINE statement and its attributes create the column definition class . (The COLUMN statement earlier in the program declared class as a column.)
GENERIC= specifies that multiple variables can use the same column definition. GENERIC= is not specific to a destination.
ID= specifies that this column should be repeated on every data panel if the report uses multiple data panels. ID= affects only the Listing output.
VJUST= specifies that the text appear at the top of the HTML table cell that it is in. VJUST= affects only the HTML output.
STYLE= specifies that the column uses the DATA table element. This table element is defined in the default style definition, which is the style definition that is being used. STYLE= affects only the HTML output.
The END statement ends the definition.
Notice that, unlike subsequent column definitions, this column definition does not include a header. This is because the same header is not appropriate for all the variables that use this column definition. Because there is no header specified here or in the FILE statement, the header comes from the label that was assigned to the variable in the DATA step.
define class; generic=on; id=on; vjust=top; style=data; end;
Create six additional columns. Each of these DEFINE statements and its attributes creates a column definition. GENERIC= specifies that multiple variables can use a column definition (although in the case of sum and mean , only one variable uses the definition). HEADER= specifies the text for the column header. VJUST= specifies that the text appear at the top of the HTML table cell that it is in. The END statement ends the definition.
define sum; generic=on; header="Total Dollars Raised"; vjust=top; end; define mean; generic=on; header="Average Dollars per Student"; vjust=top; end; define raised; generic=on; header="Individual Dollars"; end; define name; generic=on; header="Student"; end; define school; generic=on; header="School"; end; define year; generic=on; header="Year"; end;
End the table definition. This END statement ends the table definition. The RUN statement ends the PROC TEMPLATE step.
end; run;
Create the data component. This DATA step does not create a data set. Instead, it creates a data component and, eventually, an output object. The SET statement reads the data set TOP3LIST that was created with PROC MEANS.
data _null_; set top3list;
Route the DATA step results to ODS and use the means.topn table definition. The combination of the fileref PRINT and the ODS option in the FILE statement routes the results of the DATA step to ODS. (For more information on using the DATA step with ODS, see Chapter 3, 'Output Delivery System and the DATA Step,' on page 39.) The TEMPLATE= suboption tells ODS to use the table definition named means.topn , which was previously created with PROC TEMPLATE.
file print ods = ( template='means.topn'
Specify the column definition to use for each variable. The COLUMNS= suboption places DATA step variables into columns that are defined in the table definition. For example, the first column-specification specifies that the first column of the output object contains the values of the variable SCHOOL and that it uses the column definition named class . GENERIC= must be set to ON in both the table definition and each column assignment in order for multiple variables to use the same column definition.
columns=( class=school(generic=on) class=year(generic=on) sum=moneyRaised_sum(generic=on) mean=moneyRaised_mean(generic=on) raised=moneyRaised_1(generic=on) raised=moneyRaised_2(generic=on) raised=moneyRaised_3(generic=on) name=name_1(generic=on) name=name_2(generic=on) name=name_3(generic=on) school=school_1(generic=on) school=school_2(generic=on) school=school_3(generic=on) year=year_1(generic=on) year=year_2(generic=on) year=year_3(generic=on) ) );
Write the data values to the data component. The _ODS_ option and the PUT statement write the data values for all columns to the data component.
put _ods_; run;
Stop the creation of HTML output. The ODS HTML statement closes the HTML destination and all the files that are associated with it. You must close the destination before you can view the output with a browser.
ods html close;
Compare this customized output to the PROC PRINT listing output in Output 10.7.
Simple PROC PRINT of the Output Data Set 1 Top Three Fund Raisers from to Average Total Dollars Dollars per Individual Schools Years Raised Student Dollars Student School Year ____________________________________________________________________________________ Kennedy All 75.95 .73 .22 Luther Kennedy 1994 .63 Thelma Kennedy 1992 .89 Jenny Kennedy 1992 Monroe All 06.80 .69 .65 Willard Monroe 1994 .44 Cameron Monroe 1993 .87 L.T. Monroe 1994 All 1992 2.92 .48 .16 Tonya Monroe 1992 .76 Edward Monroe 1992 .63 Thelma Kennedy 1992 All 1993 7.92 .37 .44 Cameron Monroe 1993 .33 Myrtle Monroe 1993 .23 Bill Kennedy 1993 All 1994 91.91 .26 .65 Willard Monroe 1994 .22 Luther Kennedy 1994 .87 L.T. Monroe 1994 All All 82.75 .20 .65 Willard Monroe 1994 .22 Luther Kennedy 1994 .44 Cameron Monroe 1993 _______________________________________________________________________________________ (report generated on 30JUN2003)
PROC TEMPLATE features:
DEFINE TABLE statement
Table attributes:
Other ODS features:
ODS HTML statement
proc template; define table Base.Summary; notes "Summary table for MEANS and SUMMARY"; dynamic clmpct one_var_name one_var_label one_var; column class nobs id type ways (varname) (label) (min) (max) (range) (n ) (nmiss) (sumwgt) (sum) (mean) (uss) (css) (var) (stddev) (cv) ( stderr) (t) (probt) (lclm) (uclm) (skew) (kurt) (median) (mode) (q1) (q3) (qrange) (p1) (p5) (p10) (p25) (p50) (p75) (p90) (p95) (p99); define nobs; style={foreground=green}; id; end; end; run; ods html file="tmep.html"; proc summary data=sashelp.class print; class age; run; ods html close;
PROC TEMPLATE features:
DEFINE TABLE statement
NMVAR statement
NOTES statement
TRANSLATE-INTO statement
DEFINE COLUMN statement
BLANK_DUPS= attribute
CELLSTYLE-AS statement
GENERIC= attribute
Other ODS features:
ODS HTML statement
FILE statement with ODS= option
PUT statement with _ODS_ argument
Data set: GRAIN_PRODUCTION'' on page 97
Format: $CNTRY.'' on page 97
This example creates a template that uses different colors and font attributes for the text inside cells, depending on their values.
Note: This example uses filenames that might not be valid in all operating environments. To successfully run the example in your operating environment, you might need to change the file specifications. See Appendix 3, 'ODS HTML Statements for Running Examples in Different Operating Environments,' on page 649.
Set the SAS system options. The OPTIONS statement controls several aspects of the Listing output. None of these options affects the HTML output. The TITLE statement specifies a title.
options nodate pageno=1 pagesize=60 linesize=72; title 'Leading Grain Producers';
Create the table definition shared.cellstyle . The DEFINE statement creates the table definition shared.cellstyle in the first template store in the path that is available to write to. By default, this template store is SASUSER.TEMPLAT.
proc template; define table shared.cellstyle;
Specify that missing values show the text 'No data' in the report. The TRANSLATE-INTO statement translates missing values (.) into the string No data .
translate _val_=. into 'No data';
Store the information about the table in the table definition. The NOTES statement provides information about the table. NOTES statements remain a part of the compiled table definition whereas SAS comments do not.
notes "NMVAR defines symbols that will be used to determine the colors of the cells.";
Specify the symbols that reference three macro variables. The NMVAR statement defines three symbols that reference macro variables. ODS will convert the variable's values to numbers (stored as doubles) before using them. References to the macro variables are resolved when ODS binds the definition and the data component to produce an output object. The text inside quotation marks provides information about the symbols. This information becomes a part of the compiled table definition whereas SAS comments do not.
LOW, MEDIUM, and HIGH will contain the values to use as the determinants of the style element that is used to display the cell. The values are provided just before the DATA step that produces the report.
nmvar low 'Use default style.' medium 'Use yellow foreground and bold font weight' high 'Use red foreground and a bold, italic font.';
Control the repetition of values that do not change from one row to the next row. The CLASSLEVELS= attribute suppresses the display of the value in a column that is marked with BLANK_DUPS=ON if the value changes in a previous column that is also marked with BLANK_DUPS=ON. Because BLANK_DUPS= is set in a generic column, you should set this attribute as well.
classlevels=on;
Create the column char_var . The DEFINE statement and its attributes create the column definition char_var . GENERIC= specifies that multiple variables can use the same column definition. BLANK_DUPS= suppresses the display of the value in the column if it does not change from one row to the next (and, because CLASSLEVELS=ON for the table, if no value changes in a preceding column that is marked with BLANK_DUPS=ON changes).
The END statement ends the definition.
define column char_var; generic=on; blank_dups=on; end;
Create the column num_var . The DEFINE statement and its attributes create the column definition num_var . GENERIC= specifies that multiple variables can use the same column definition.
define column num_var; generic=on;
Align the values in the column without regard to the format field. JUSTIFY= justifies the values in the column without regard to the format field. For numeric variables, the default justification is RIGHT, so even the translated character value No data that is used for missing values is right-justified. Without JUSTIFY=ON in this column definition, the value No data is formatted as a character variable (left-justified) within a format field that has the same width as the column.
justify=on;
Specify which style element and style attributes to use for different values in the column. The CELLSTYLE-AS statement specifies the style element and style attributes to use for different values in this column. If a value is less than or equal to the value of the variable LOW, the cell uses the unaltered Data style element. If a value is greater than LOW but less than or equal to the value of MEDIUM, the cell uses the style element Data with a foreground color of green and an italic font. Similarly, other values use a foreground color of yellow or red and combinations of a bold font weight and an italic font style. The CELLSTYLE-AS statement affects only the HTML destination.
The END statement ends the column definition.
cellstyle _val_ <= low as data, _val_ <= medium as data {foreground=green font_style=italic}, _val_ <= high as data {foreground=yellow font_weight=bold}, 1 as data {foreground=red font_style=italic font_weight=bold}; end;
End the table definition. This END statement ends the table definition. The RUN statement ends the PROC TEMPLATE step.
end; run;
Create the HTML output and specify name of the HTML file. The ODS HTML statement opens the HTML destination and creates HTML output. It sends all output objects to the external file cellstyle-body.htm in the current directory. Some browsers require an extension of .htm or .html on the filename.
ods html body='cellstyle-body.htm';
Assign values to three macro variables. The %LET statements assign values to the macro variables LOW, MEDIUM, and HIGH.
%let low=10000; %let medium=50000; %let high=100000;
Create the data component. This DATA step does not create a data set. Instead, it creates a data component, and, eventually, an output object. The SET statement reads the data set GRAIN_PRODUCTION.
data _null_; set grain_production;
Route the DATA step results to ODS and use the shared.cellstyle table definition. The combination of the fileref PRINT and the ODS option in the FILE statement routes the results of the DATA step to ODS. (For more information on using the DATA step with ODS, see Chapter 3, 'Output Delivery System and the DATA Step,' on page 39.) The TEMPLATE= suboption tells ODS to use the table definition named shared.cellstyle , which was previously created with PROC TEMPLATE.
file print ods=( template='shared.cellstyle'
Specify the column definition to use for each variable. The COLUMNS= suboption places DATA step variables into columns that are defined in the table definition. For example, the first column-specification specifies that the first column of the output object contains the values of the variable YEAR and that it uses the column definition named char_var . GENERIC= must be set to ON, both in the table definition and in each column assignment, in order for multiple variables to use the same column definition.
columns=( char_var=year(generic=on) char_var=country(generic=on format=$cntry.) char_var=type(generic=on) num_var=kilotons(generic=on format=comma12.) ) );
Write the data values to the data component. The _ODS_ option and the PUT statement write the data values for all columns to the data component.
put _ods_; run;
Stop the creation of HTML output. The ODS HTML statement closes the HTML destination and all the files that are associated with it. You must close the destination before you can view the output with a browser.
ods html close;
Only the table customizations appear in the Listing output. Table customizations include the suppression of values that do not change from one row to the next and the translation of missing values to No data . The style customizations that are specified in the CELLSTYLE-AS statement do not appear in the Listing output.
Leading Grain Producers 1 Year Country Type Kilotons 1995 Brazil Corn 36,276 Rice 11,236 Wheat 1,516 China Corn 112,331 Rice 185,226 Wheat 102,207 India Corn 9,800 Rice 122,372 Wheat 63,007 Indonesia Corn 8,223 Rice 49,860 Wheat No data United States Corn 187,300 Rice 7,888 Wheat 59,494 1996 Brazil Corn 31,975 Rice 10,035 Wheat 3,302 China Corn 119,350 Rice 190,100 Wheat 109,000 India Corn 8,660 Rice 120,012 Wheat 62,620 Indonesia Corn 8,925 Rice 51,165 Wheat No data United States Corn 236,064 Rice 7,771 Wheat 62,099
Both the table customizations and the style customizations appear in the HTML output. Table customizations include the suppression of values that do not change from one row to the next, and the translation of missing values to No data . The style customizations include the colors and font styles that are specified in the CELLSTYLE-AS statement.
PROC TEMPLATE features:
DEFINE STYLE statement
REPLACE statement
DEFINE TABLE statement
CELLSYTLE-AS statement
DEFINE COLUMN statement
DEFINE HEADER statement
TEXT statement
DEFINE HEADER statement
TEXT statement
Other ODS features:
FILE statement with ODS= option
ODS HTML statement
STYLE= option
ODS PDF statement
STYLE= option
PUT statement with _ODS_ argument
ODS TRACE statement
This example combines a customized style definition with a customized table definition to produce output with a checkerboard pattern of table cells.
Create a new style definition Greenbar . The PROC TEMPLATE statement starts the TEMPLATE procedure. The DEFINE STYLE statement creates a new style definition greenbar .
proc template; define style greenbar;
Specify the parent style definition from which the greenbar style definition inherits its attributes. The PARENT= attribute specifies the style definition from which the greenbar definition inherits its style elements and attributes. All the style elements and their attributes that are specified in the parent's definition are used in the current definition unless the current definition overrides them.
parent=styles.printer;
Change the colors used in the headers and footers. The REPLACE statement adds a style element to the greenbar style definition from the parent style definition, but the background is light green and the foreground is black.
replace headersandfooters from cell / background=light green foreground=black ;
End the style definition. The END statement ends the style definition. The RUN statement executes the PROC TEMPLATE step.
end; run;
Create the HTML and PDF output and specify the style definition that you want to use for the output. The ODS HTML statement opens the HTML destination and creates HTML output. It sends all output objects to the file greenbar.html in the current directory. The STYLE= option tells ODS to use greenbar as the style definition when it formats the output.
The ODS PDF statement opens the PDF destination and creates PDF output. It sends all output objects to the file greenbar.pdf in the current directory. The STYLE= option tells ODS to use greenbar as the style definition when it formats the output.
ods html body="greenbar.html" style=greenbar; ods pdf file="greenbar.pdf" style=greenbar;
Create the table definition Checkerboard . The DEFINE statement creates the table definition Checkerboard in the first template store in the path that is available to write to. By default, this template store is SASUSER.TEMPLAT.
proc template; define table Checkerboard;
Specify which style element and style attributes to use for different cells.
The CELLSTYLE-AS statement specifies the style element and style attributes to use for cells in each of the rows and columns. The CELLSTYLE-AS statement creates the checkerboard effect in the output. If both the row and column are odd numbered, then the cell is magenta in color. Similarly, if both the row and column are even numbered, then the cell is magenta in color. The CELLSTYLE-AS statement has no effect on the LISTING destination because it is changing style elements and style attributes which have no effect in listing output.
cellstyle mod(_row_,2) && mod(_col_,2) as data{background=magenta}, not(mod(_row_,2)) && not(mod(_col_,2)) as data{background=magenta}, 1 as data;
Create the header definition top . The DEFINE HEADER statement defines the table header top .
The TEXT statement specifies the text of the header Checkerboard Table Definition .
The END statement ends the header definition.
define header top; text 'Checkerboard Table Definition'; end;
Create the column definition name . The DEFINE COLUMN statement creates the column definition name .
The DEFINE HEADER statement creates the header definition bar .
The TEXT statement specifies the text to use in the header. _LABEL_ is a dynamic variable that references a value that the data component supplies from the procedure or DATA step, in this example the variable's label.
The first END statement ends the header definition.
The HEADER statement declares bar as the header in the table.
The second END statement ends the column definition.
define column name; define header bar; text "begin " _label_ " end"; end; header=bar; end;
Create the column definition gender . The DEFINE COLUMN statement creates the column definition gender .
The DATANAME= column attribute specifies the name of the column sex in the data component to associate with the column definition gender .
The DEFINE HEADER statement creates the header bar .
The TEXT statement specifies the text Gender to use in the header.
The first END statement ends the header definition.
The HEADER statement declares bar as the header in the table.
The second END statement ends the column definition.
define column gender; dataname=sex; define header bar; text "Gender"; end; header=bar; end;
Create three column definitions: age , height , and weight . The three DEFINE COLUMN statements create the column definitions age , weight , and height .
The END statement ends the column definition.
define column age; end; define column height; end; define column weight; end;
End the table definition. The END statement ends the table definition. The RUN statement executes the TEMPLATE procedure.
end; run;
Create the data component. This DATA step does not create a data set. Instead, it creates a data component that is used to produce an output object.
The SET statement reads the data set SASHELP.CLASS .
data _null_; set sashelp.class;
Route the DATA step results to ODS and use the Checkerboard table definition. The combination of the fileref PRINT and the ODS option in the FILE statement routes the results of the DATA step to ODS. (For more information about using the DATA step with ODS, see Chapter 3, 'Output Delivery System and the DATA Step,' on page 39.) The TEMPLATE= suboption tells ODS to use the table definition named Checkerboard .
file print ods=(template='Checkerboard'); put _ods_; run;
Stop the creation of HTML and PDF output. The ODS HTML statement closes the HTML destination and all the files that are associated with it. The ODS PDf statement closes the PDF destination and all the files that are associated with it. You must close the destinations before you can view the output.
ods html close; ods pdf close;