Previous Page | Next Page

TEMPLATE Procedure: Creating Tabular Output

Example 3: Creating a New Table Template


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

Data set: Charity.


Program Description

This example creates a custom table template 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 ODS HTML Statements for Running Examples in Different Operating Environments.  [cautionend]


Program 1: Producing an Output Data Set with PROC MEANS

 Note about code
options nodate pageno=1 pagesize=60 linesize=72;
 Note about code
proc format;
   value yrFmt . = " All";
   value $schFmt " " = "All    ";
   run;
 Note about code
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;
 Note about code
proc print data=top3list noobs;
   title "Simple PROC PRINT of the Output Data Set";
run;

Listing Output from PROC PRINT

PROC PRINT Listing Output from PROC MEANS

                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  $1575.95   $29.73   $72.22   $52.63   $43.89
Monroe   All   10      56  $1616.80   $28.87   $78.65   $65.44   $56.87
All     1992   01      31   $892.92   $28.80   $55.16   $53.76   $52.63
All     1993   01      32   $907.92   $28.37   $65.44   $47.33   $42.23
All     1994   01      46  $1391.91   $30.26   $78.65   $72.22   $56.87
All      All   00     109  $3192.75   $29.29   $78.65   $72.22   $65.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 

Program 2: Building a Custom Table Template for the TopN Report

 Note about code
options nodate pageno=1 pagesize=60 linesize=72;
 Note about code
ods html body="Topn-Body.htm";
 Note about code
proc template;
   define table means.topn;
 Note about code
   mvar first_year last_year sysdate9;
 Note about code
   column class sum mean (raised) (name) (school) (year);
 Note about code
    double_space=on;
    overline=on;
    underline=on;
 Note about code
   header table_header_1 table_header_2;
   
 Note about code
   define table_header_1;
      text "Top Three Fund Raisers";
      style=header{fontsize=6};
   end;
 Note about code
  define table_header_2;
      text "from " first_year " to " last_year;
      space=1;
  end;
 Note about code
   define footer table_footer;
      text "(report generated on " sysdate9 ")";
      split="*";
      style=header{fontsize=2};
   end;
 Note about code
   define class;
      generic=on;
      id=on;
      vjust=top;
      style=data;
   end;
 Note about code
   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;
 Note about code
   end;
run;
 Note about code
data _null_;
   set top3list;
 Note about code
   file print ods = (
      template="means.topn"
 Note about code
      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)
         )
      );
 Note about code
put _ods_;
run;
 Note about code
ods html close;

listing output for the TopN Report

Compare this customized output to the PROC PRINT listing output in PROC PRINT Listing Output from PROC MEANS.

Using a Customized Table to Produce Listing Output

   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  $1575.95    $29.73      $72.22  Luther   Kennedy  1994
                                         $52.63  Thelma   Kennedy  1992
                                         $43.89  Jenny    Kennedy  1992

 Monroe     All  $1606.80    $28.69      $78.65  Willard  Monroe   1994
                                         $65.44  Cameron  Monroe   1993
                                         $56.87  L.T.     Monroe   1994

 All       1992   $882.92    $28.48      $55.16  Tonya    Monroe   1992
                                         $53.76  Edward   Monroe   1992
                                         $52.63  Thelma   Kennedy  1992

 All       1993   $907.92    $28.37      $65.44  Cameron  Monroe   1993
                                         $47.33  Myrtle   Monroe   1993
                                         $42.23  Bill     Kennedy  1993

 All       1994  $1391.91    $30.26      $78.65  Willard  Monroe   1994
                                         $72.22  Luther   Kennedy  1994
                                         $56.87  L.T.     Monroe   1994

 All        All  $3182.75    $29.20      $78.65  Willard  Monroe   1994
                                         $72.22  Luther   Kennedy  1994
                                         $65.44  Cameron  Monroe   1993
____________________________________________________________________________
                    (report generated on 30JUN2003)             

HTML Output: Using a Customized Table for the TopN Report

HTML Output for the TopN Report (Viewed with Microsoft Internet Explorer)

[HTML Output  for the TopN Report (Viewed with Microsoft Internet Explorer)]

Previous Page | Next Page | Top of Page