• Output delivery system (ODS)

The Output Delivery System is a set of SAS commands that allow users to manage the

output of their programs and procedures. Using ODS, one can:

  1. routing output to HTML, RTF, and PDF files
  2. select and exclude output tables from display
  3. create SAS datasets directly from output tables
  4. export SAS datasets to CSV or HTML files
  • Output object: the building element of output of a procedure

In order to control the output of a procedure, one needs to know the names of output objects. To check on the names of the output objects a procedure produces, use the command:

ods trace on;

PROC blah data=dataset;

Statements;

run;

ods trace off;

The names will be displayed in the log window.

data htwt;

input subject gender $ height weight score $;

datalines;

1 M 68.5 155 L

2 F 61.2 99 H

3 F 63.0 115 M

4 M 70.0 205 .

5 M 68.6 170 M

6 F 65.1 125 H

7 M 72.4 220 L

8 M . 188 H

;

odstraceon;

procfreqdata=htwt;

tables gender/bin;

run;

odstraceoff;

Note the run statement comes before the ODS TRACE OFF statement. Unlike most other SAS statements,the ODS statement executes immediately, if the ODS TRACE OFF is put before the run statement, thetrace would turn off before the procedure runs.

  • Output selection:Once we know what are the output objects, we can select parts of the output using:

ods select output-object(s);

The PROC step with the output objects you want to select

run;

Here output-object(s) can be identified by its name, label or path.

odsselect BinomialProp;

procfreqdata=htwt;

tables gender/bin;

run;

ods select statement works for the procedure immediately following it or the procedure

immediately proceding it if it is right before a run statement.

odsexclude OneWayFreqs BinomialPropTest;

procfreqdata=htwt;

tables gender/bin;

run;

  • Output routing: changing the destination of the output

Destinations: listing(the default), html, rtf, pdf, csv

ODS destination;

Proc BLAH data=HI;

RUN;

ODS destination close;

odshtmlpath='C:\Documents and Settings\anna\Desktop\MyDesktop\597.F10\'body='htwt.html';

/* contents='contents.html'

page='page.html'

frame='frame.html'

gpath='C:\Documents and Settings\anna\Desktop\MyDesktop\597.F10';*/

title'Height and weight';

procunivariatedata=htwt plotnormal;

class gender;

probplot height;

procprintdata=htwt;

run;

odshtmlclose;

filename reports 'C:\Documents and Settings\anna\Desktop\MyDesktop\597.F10\htwt.html'mod;

data_null_;

file reports;

put"<h2>The preceding output is from PROC PRINT.";

put"I am going to try a variety of procedures.";

put"Let me know which procedure you prefer.</h2>";

run;

odshtmlbody=reports;

procfreqdata=htwt;

tables gender/bin;

run;

odshtmlclose;

odsselect moments;

ods pdf file='C:\Documents and Settings\anna\Desktop\MyDesktop\597.F10\htwt.pdf';

title'Height and weight';

procunivariatedata=htwt plotnormal;

class gender;

probplot height;

procprintdata=htwt;

run;

ods pdf close;

Use ods csv or ods html in conjunction with the print procedure to export SAS datasets

odscsvfile='htwt.csv';

procprintdata=csv;

run;

odscsvclose;

  • Creating a SAS data sets from procedure output using

ods output output-object=new-data-set;

The placement of the ODS OUTPUT statement follows the same rule as that of the ODS SELECT

odsoutput BinomialProp=PropCI;

procfreqdata=htwt;

tables gender/bin;

procprintdata=PropCI;

run;

odsoutput basicmeasures=measure;

procunivariatedata=htwt;

var weight;

run;

procprintdata=measure;run;

  • Writing data to external files
  1. Writing SAS datasets to a raw data file

data one;

input id $ score1-score5;

datalines;

001 64 69 68 82 74

002 80 80 80 60 80

;

data_null_;

file'C:\Documents and Settings\anna\Desktop\MyDesktop\597.F10\temp.dat';

set one;

put id $ @10 (score1-score5) (4.);

run;

Append data to a file

filename tempfile 'C:\Documents and Settings\anna\Desktop\MyDesktop\597.F10\temp.dat'mod;

data_NULL_;

file tempfile;

put"you can write any text here"

/ "Another line of text";

do i=1to10;

a = ranuni(0);

put a 5.2;

end;

run;

  1. Writing SAS datasets to a delimited file or PC file with procedure export

Proc export data=SAS dataset outfile=’filename’ DBMS=identifier REPLACE;

Delimiter=delimiter;

Some options for DBMS identifier: csv, tab, dlm, excel

If DBMS=dlm, one has to supply the delimiter, for example, delimiter=’&’.

If file has extension csv, txt, xls or dbf, SAS will automatically determine delimiter, in which case, specification of DBMS and Delimiter is not necessary.

data one;

input id $ score1-score5;

datalines;

001 64 69 68 82 74

002 80 80 80 60 80

;

procexportdata=one outfile='C:\Documents and Settings\anna\Desktop\MyDesktop\597.F10\one.csv';

run;

  1. Writing SAS datasets to a delimited file or PC file with the export wizard