Example 1: Creating a Report with the DATA Step and the Default Table Definition

Features:

FILE PRINT ODS statement

PUT _ODS_ statement

ODS destination: HTML

Details

This example uses the DATA step and ODS to create an HTML report. It uses the default table definition (template) for the DATA step and writes an output object to the HTML destination (the default).

Program

options nodate pageno=1 linesize=64 pagesize=60 obs=15;
title 'Leading Grain Producers';
proc format;
   value $cntry 'BRZ'='Brazil'
                'CHN'='China'
                'IND'='India'
                'INS'='Indonesia'
                'USA'='United States';
run;
data _null_;
   
   length Country $ 3 Type $ 5;
   format country $cntry.;
   label type='Grain';
   input Year country $ type $ Kilotons;
   
   file print ods;
   put _ods_;
   datalines;
1995 BRZ  Wheat    1516
1995 BRZ  Rice     11236
1995 BRZ  Corn     36276
1995 CHN  Wheat    102207
1995 CHN  Rice     185226
1995 CHN  Corn     112331
1995 IND  Wheat    63007
1995 IND  Rice     122372
1995 IND  Corn     9800
1995 INS  Wheat    .
1995 INS  Rice     49860
1995 INS  Corn     8223
1995 USA  Wheat    59494
1995 USA  Rice     7888
1995 USA  Corn     187300
1996 BRZ  Wheat    3302
1996 BRZ  Rice     10035
1996 BRZ  Corn     31975
1996 CHN  Wheat    109000
1996 CHN  Rice     190100
1996 CHN  Corn     119350
1996 IND  Wheat    62620
1996 IND  Rice     120012
1996 IND  Corn     8660
1996 INS  Wheat    .
1996 INS  Rice     51165
1996 INS  Corn     8925
1996 USA  Wheat    62099
1996 USA  Rice     7771
1996 USA  Corn     236064
;
run;

Program Description

Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. The PAGENO= option specifies the starting page number. The LINESIZE= option specifies the output line length, and the PAGESIZE= option specifies the number of lines on an output page. The OBS= option specifies the number of observations to print.
options nodate pageno=1 linesize=64 pagesize=60 obs=15;
Specify a title. The TITLE statement specifies a title for the output.
title 'Leading Grain Producers';
Create a user-defined format. PROC FORMAT creates the format $CNTRY. for the variable COUNTRY.
proc format;
   value $cntry 'BRZ'='Brazil'
                'CHN'='China'
                'IND'='India'
                'INS'='Indonesia'
                'USA'='United States';
run;
Begin a DATA step that does not create an output data set. Using _NULL_ saves computer resources because it prevents the DATA step from creating an output data set.
data _null_;
   
Define variables, assign lengths and formats, read a record, and assign values to four variables. The LENGTH statement defines a length that is shorter than the default to two character variables. The FORMAT statement assigns a user-defined format to the variable COUNTRY. The LABEL statement assigns a label to the variable TYPE. The INPUT statement reads a record from the data lines and assigns a value to four variables.
   length Country $ 3 Type $ 5;
   format country $cntry.;
   label type='Grain';
   input Year country $ type $ Kilotons;
   
Use the default table definition (template) to create HTML output. The combination of the fileref PRINT and the ODS option in the FILE statement routes the DATA step output to ODS. The only open ODS destination is the HTML destination, which is open by default when you begin your SAS session. Because no suboptions are specified, ODS uses the default DATA step table definition (template). This FILE PRINT ODS statement creates an output object and binds it to the default template.
   file print ods;
Write the variables to the data component. The _ODS_ option in the PUT statement writes every variable to the buffer that the PUT statement writes to the data component. Because no formats or labels are specified for individual columns, ODS uses the defaults.
   put _ods_;
The data provide information about the amounts of wheat, rice, and corn that five leading grain-producing nations produced during 1995 and 1996.
   datalines;
1995 BRZ  Wheat    1516
1995 BRZ  Rice     11236
1995 BRZ  Corn     36276
1995 CHN  Wheat    102207
1995 CHN  Rice     185226
1995 CHN  Corn     112331
1995 IND  Wheat    63007
1995 IND  Rice     122372
1995 IND  Corn     9800
1995 INS  Wheat    .
1995 INS  Rice     49860
1995 INS  Corn     8223
1995 USA  Wheat    59494
1995 USA  Rice     7888
1995 USA  Corn     187300
1996 BRZ  Wheat    3302
1996 BRZ  Rice     10035
1996 BRZ  Corn     31975
1996 CHN  Wheat    109000
1996 CHN  Rice     190100
1996 CHN  Corn     119350
1996 IND  Wheat    62620
1996 IND  Rice     120012
1996 IND  Corn     8660
1996 INS  Wheat    .
1996 INS  Rice     51165
1996 INS  Corn     8925
1996 USA  Wheat    62099
1996 USA  Rice     7771
1996 USA  Corn     236064
;
run;

HTML Output

The default table definition produces a column for each variable in the DATA step. The order of the columns is determined by their order in the program data vector. Because no attributes are specified for individual columns, ODS uses the default column headings and formats.
Default HTML Output
HTML Output The default table definition produces a column for each variable in the DATA step.