Previous Page | Next Page

Output Delivery System and the DATA Step

Examples


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

ODS features:

FILE PRINT ODS statement

PUT _ODS_ statement

ODS destinations:

LISTING

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


Program

 Note about code
options nodate pageno=1 linesize=64 pagesize=60;
 Note about code
title 'Leading Grain Producers';
 Note about code
proc format;
   value $cntry 'BRZ'='Brazil'
                'CHN'='China'
                'IND'='India'
                'INS'='Indonesia'
                'USA'='United States';
run;
 Note about code
data _null_;
   
 Note about code
   length Country $ 3 Type $ 5;
   format country $cntry.;
   label type='Grain';
   input Year country $ type $ Kilotons;
   
 Note about code
   file print ods;
 Note about code
   put _ods_;
 Note about code
   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
;

Listing Output

Listing Output Created with the Default DATA Step Table Definition

 Note about figure
                    Leading Grain Producers                    1
        Country       Grain        Year          Kilotons

     Brazil           Wheat            1995            1516
     Brazil           Rice             1995           11236
     Brazil           Corn             1995           36276
     China            Wheat            1995          102207
     China            Rice             1995          185226
     China            Corn             1995          112331
     India            Wheat            1995           63007
     India            Rice             1995          122372
     India            Corn             1995            9800
     Indonesia        Wheat            1995               .
     Indonesia        Rice             1995           49860
     Indonesia        Corn             1995            8223
     United States    Wheat            1995           59494
     United States    Rice             1995            7888
     United States    Corn             1995          187300
     Brazil           Wheat            1996            3302
     Brazil           Rice             1996           10035
     Brazil           Corn             1996           31975
     China            Wheat            1996          109000
     China            Rice             1996          190100
     China            Corn             1996          119350
     India            Wheat            1996           62620
     India            Rice             1996          120012
     India            Corn             1996            8660
     Indonesia        Wheat            1996               .
     Indonesia        Rice             1996           51165
     Indonesia        Corn             1996            8925
     United States    Wheat            1996           62099
     United States    Rice             1996            7771
     United States    Corn             1996          236064

Example 2: Producing ODS Output That Contains Selected Variables

ODS features:

FILE PRINT ODS statement:

VARIABLES= suboption

ODS HTML statement:

BODY= option

URL= suboption

PUT _ODS_ statement

ODS destinations:

HTML

LISTING

Format:

$CNTRY. .

This example selects variables to include in the output. The resulting output is produced in two formats, listing and HTML. The listing output is produced by default, and the HTML output is requested by the ODS HTML statement.

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

 Note about code
options nodate pageno=1 linesize=64 pagesize=60;
 Note about code
ods html body='your-html-file.html';
 Note about code
title 'Leading Grain Producers'; 
title2 'for 1996'; 
 Note about code
data _null_;
         
 Note about code
   length Country $ 3 Type $ 5;
   format country $cntry.;
   label type='Grain';
 Note about code
   input Year country $ type $ Kilotons;
   if year=1996;
 Note about code
   file print ods=(variables=(country
                              type
                              kilotons));
 Note about code
      put _ods_;
 Note about code
   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
;
 Note about code
ods html close;

HTML Output

HTML Body File Produced by ODS

[HTML Body File Produced by ODS]


Listing Output

Listing Output Produced by the LISTING Destination

                    Leading Grain Producers                    1
                            for 1996
                Country       Grain      Kilotons

             Brazil           Wheat            3302
             Brazil           Rice            10035
             Brazil           Corn            31975
             China            Wheat          109000
             China            Rice           190100
             China            Corn           119350
             India            Wheat           62620
             India            Rice           120012
             India            Corn             8660
             Indonesia        Wheat               .
             Indonesia        Rice            51165
             Indonesia        Corn             8925
             United States    Wheat           62099
             United States    Rice             7771
             United States    Corn           236064

Example 3: Assigning Attributes to Columns in ODS Output

ODS features:

FILE PRINT ODS statement:

OBJECTLABEL= suboption

VARIABLES= suboption

LABEL= suboption

FORMAT= suboption

PUT _ODS_ statement

ODS destinations:

HTML

LISTNG

PRINTER (PS)

Format:

$CNTRY. .

This example assigns a label to the output object that it creates. It also specifies a label and a format for individual columns.

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

 Note about code
options pagesize=60 linesize=64 nodate pageno=1;
 Note about code
ods html body='your_body_file.html'
         contents='your_contents_file.html'
         frame='your_frame_file.html';
 Note about code
ods printer file='your_postscript_file.ps';
 Note about code
title 'Leading Grain Producers'; 
title2 'for 1996'; 
 Note about code
data _null_;
         
 Note about code
   length Country $ 3 Type $ 5;
   format country $cntry.;
   label type='Grain';
 Note about code
   input Year country $ type $ Kilotons;
   if year=1996;
 Note about code
   file print ods= (objectlabel='1996 Grain Production'
           variables=(country
                      type(label='Type of Grain')
                      kilotons(format=comma12.))
      );
 Note about code
   put _ods_;
 Note about code
   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
;
 Note about code
ods _all_ close;

HTML Output

HTML Frame File Produced by ODS

 Note about figure

[HTML Frame File Produced by ODS]


Printer Output

Printer Output Viewed with Ghostview

 Note about figure

[Printer Output Viewed with Ghostview]


Listing Output

 Note about figure
                    Leading Grain Producers                    1
                            for 1996
                              Type
                               of
                Country       Grain      Kilotons

             Brazil           Wheat           3,302
             Brazil           Rice           10,035
             Brazil           Corn           31,975
             China            Wheat         109,000
             China            Rice          190,100
             China            Corn          119,350
             India            Wheat          62,620
             India            Rice          120,012
             India            Corn            8,660
             Indonesia        Wheat               .
             Indonesia        Rice           51,165
             Indonesia        Corn            8,925
             United States    Wheat          62,099
             United States    Rice            7,771
             United States    Corn          236,064

Example 4: Creating and Using a User-Defined Table Definition Template

ODS features:

PROC TEMPLATE

FILE PRINT ODS statement:

COLUMNS= suboption:

FORMAT= suboption

DYNAMIC= suboption

GENERIC= suboption

TEMPLATE=

PUT _ODS_ statement:

column pointer controls

line pointer controls

ODS destination:

RTF

This example shows how to do the following:

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: Creating the User-Defined Table Definition (Template)

 Note about code
proc template;
define table phonelist;
      column name phone;
      dynamic colheader;
   define name;
      generic=on;
      header=colheader;

      style=data{fontstyle=italic fontsize=5};
   end;

   define phone;
      header='Telephone';
      style=datafixed;
   end;
end;
run;

Program: Using the User-Defined Template (Table Definition)

 Note about code
ods listing close;
 Note about code
ods rtf body='your_rtf_file.rtf';
 Note about code
title 'New Subscriber Telephone List';
 Note about code
proc format;
   picture phonenum .='Not available'
                other='0000)000-0000' (prefix='(');
run;
 Note about code
data phones;
   length first_name $20 last_name $25;
   input first_name $ last_name $ business_phone home_phone;
   datalines;
Jerome Johnson 9193191677 9198462198
Romeo Montague 8008992164 3609736201
Imani Rashid 5088522146 5083669821
Palinor Kent . 9197823199
Ruby Archuleta . .
Takei Ito 7042982145 .
Tom Joad 2099632764 2096684741
;
 Note about code
proc sort data=phones;
   by last_name;
run;
 Note about code
data _null_;
    set phones;
 Note about code
file print ods=(template='phonelist'
 Note about code
                columns=
                         (name=last_name
                           (generic=on
                            dynamic=(colheader='Last Name'))
                          name=first_name
                           (generic=on
                            dynamic=(colheader='First Name'))
                          phone=business_phone
                            (format=phonenum.)
                          )
               );
 Note about code
if (missing(business_phone)) then
   put _ods_ @3 home_phone;
else if (missing(home_phone)) then 
   put _ods_;
else
   put _ods_ / @3 home_phone;
run;
 Note about code
ods RTF close;

RTF Output

RTF Output Viewed with Microsoft Word

[RTF Output Viewed with Microsoft Word]

Previous Page | Next Page | Top of Page