A Quick Start to Using ODS

The Purpose of These Examples

The following examples are designed to help you to begin using ODS quickly. Use them to learn how to produce output that contains more interesting formatting. Then, to learn more about the depth, breadth, and true power of ODS, see Introduction to the Output Delivery System.

Creating HTML Output

Creating HTML output is simple—just run a DATA step or PROC step as usual. By default, the HTML destination is on, and the DATA step and Base SAS procedures create HTML output through ODS. You can browse this output with Internet Explorer, Netscape, or any other browser that fully supports HTML 3.2 or later. You can choose which output to view in the Results window.
options source pagesize=60 linesize=80 nodate;

data employee_data;
   input IDNumber $ 1-4 LastName $ 9-19 FirstName $ 20-29
         City $ 30-42 State $ 43-44 /
         Gender $ 1 JobCode $ 9-11 Salary 20-29 @30 Birth date9.
         @43 Hired date9. HomePhone $ 54-65;
   format birth hired date9.;

            datalines;
1919    Adams      Gerald    Stamford     CT
M       TA2        34376     15SEP48      07JUN75    203/781-1255
1653    Alexander  Susan     Bridgeport   CT
F       ME2        35108     18OCT52      12AUG78    203/675-7715
1400    Apple      Troy      New York     NY
M       ME1        29769     08NOV55      19OCT78    212/586-0808
1350    Arthur     Barbara   New York     NY
F       FA3        32886     03SEP53      01AUG78    718/383-1549
1401    Avery      Jerry     Paterson     NJ
M       TA3        38822     16DEC38      20NOV73    201/732-8787
1499    Barefoot   Joseph    Princeton    NJ
M       ME3        43025     29APR42      10JUN68    201/812-5665
1101    Baucom     Walter    New York     NY
M       SCP        18723     09JUN50      04OCT78    212/586-8060
1333    Blair      Justin    Stamford     CT
M       PT2        88606     02APR49      13FEB69    203/781-1777
1402    Blalock    Ralph     New York     NY
M       TA2        32615     20JAN51      05DEC78    718/384-2849
1479    Bostic     Marie     New York     NY
F       TA3        38785     25DEC56      08OCT77    718/384-8816
1403    Bowden     Earl      Bridgeport   CT
M       ME1        28072     31JAN57      24DEC79    203/675-3434
1739    Boyce      Jonathan  New York     NY
M       PT1        66517     28DEC52      30JAN79    212/587-1247
1658    Bradley    Jeremy    New York     NY
M       SCP        17943     11APR55      03MAR80    212/587-3622
1428    Brady      Christine Stamford     CT
F       PT1        68767     07APR58      19NOV79    203/781-1212
1407    Grant      Daniel    Mt. Vernon   NY
M       PT1        68096     26MAR57      21MAR78    914/468-1616
1114    Green      Janice    New York     NY
F       TA2        32928     21SEP57      30JUN75    212/588-1092
;

proc print data=employee_data(obs=12);
   id idnumber;
   title 'Personnel Data';
run; 
HTML output is the default format. Therefore, when you request another format, your programs will create both HTML output and output in the requested format. To prevent HTML output from being created, use this statement:
ods html close;
Default HTML Output
Default HTML Output

Creating LISTING Output

You can create traditional SAS output with monospace fonts (LISTING output) by using the ODS LISTING statement.
The following program contains a PROC PRINT step that produces LISTING output, but does not produce the default HTML output.
  
ods html close;
ods listing;
proc print data=employee_data(obs=12);
   id idnumber;
   title 'Personnel Data';
run;

ods listing close;
ods html;
Note the two ODS statements that follow the PROC PRINT step. To be able to view your LISTING output, you must execute the ODS LISTING CLOSE statement. It is simply good practice to reset ODS to HTML output, which is the default setting.
Default Listing Output
                                 Personnel Data                                1

                            First                                        Job
   IDNumber    LastName     Name           City       State    Gender    Code

     1919      Adams        Gerald      Stamford       CT        M       TA2
     1653      Alexander    Susan       Bridgeport     CT        F       ME2
     1400      Apple        Troy        New York       NY        M       ME1
     1350      Arthur       Barbara     New York       NY        F       FA3
     1401      Avery        Jerry       Paterson       NJ        M       TA3
     1499      Barefoot     Joseph      Princeton      NJ        M       ME3
     1101      Baucom       Walter      New York       NY        M       SCP
     1333      Blair        Justin      Stamford       CT        M       PT2
     1402      Blalock      Ralph       New York       NY        M       TA2
     1479      Bostic       Marie       New York       NY        F       TA3
     1403      Bowden       Earl        Bridgeport     CT        M       ME1
     1739      Boyce        Jonathan    New York       NY        M       PT1


   IDNumber    Salary        Birth        Hired     HomePhone

     1919       34376    15SEP1948    07JUN1975    203/781-1255
     1653       35108    18OCT1952    12AUG1978    203/675-7715
     1400       29769    08NOV1955    19OCT1978    212/586-0808
     1350       32886    03SEP1953    01AUG1978    718/383-1549
     1401       38822    16DEC1938    20NOV1973    201/732-8787
     1499       43025    29APR1942    10JUN1968    201/812-5665
     1101       18723    09JUN1950    04OCT1978    212/586-8060
     1333       88606    02APR1949    13FEB1969    203/781-1777
     1402       32615    20JAN1951    05DEC1978    718/384-2849
     1479       38785    25DEC1956    08OCT1977    718/384-8816
     1403       28072    31JAN1957    24DEC1979    203/675-3434
     1739       66517    28DEC1952    30JAN1979    212/587-1247

Producing Output in Multiple Formats at the Same Time

A simple way to produce output in multiple formats at one time is to produce the default HTML output and then request an additional format, such as LISTING, PDF, RTF, or PostScript.
ods html
file='HTML-file-pathname.html';
ods pdf file='PDF-file-pathname.pdf';
ods rtf file='RTF-file-pathname.rtf';
ods ps file='PS-file-pathname.ps';
proc print data=employee_data(obs=12);
   id idnumber;
   title 'Personnel Data';
run;

ods  _all_  close;
ods listing;
Note the two ODS statements that follow the PROC statement. The first one closes all files so that you can use them (for example, you could browse the HTML file or send the PDF file to a printer). The final statement opens the LISTING destination so that ODS returns to producing LISTING output for subsequent DATA or PROC steps in the current session.
The following output is formatted in HTML 3.2 output and viewed in an Internet Explorer browser.
HTML 3.2 Output
HTML Output
The following output is formatted in PDF and viewed with Adobe Acrobat Reader.
PDF Output
PDF Output
The following RTF output is viewed with Microsoft Word.
RTF Output
RTF Output
The following output is traditional SAS LISTING output.
LISTING Output
LISTING Output