Docstoc

Output delivery system ODS

Document Sample
Output delivery system ODS Powered By Docstoc
					 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
              ;
              ods trace on;
              proc freq data=htwt;
                    tables gender/bin;
              run;
              ods trace off;
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, the trace 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.

              ods select BinomialProp;
              proc freq data=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.
              ods exclude OneWayFreqs BinomialPropTest;
              proc freq data=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;

              ods html path='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';
              proc univariate data=htwt plot normal;
                    class gender;
                    probplot height;
              proc print data=htwt;
              run;
              ods html close;

              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;

              ods html body=reports;
              proc freq data=htwt;
                    tables gender/bin;
              run;
              ods html close;

              ods select moments;
              ods pdf file='C:\Documents and
              Settings\anna\Desktop\MyDesktop\597.F10\htwt.pdf';
              title 'Height and weight';
              proc univariate data=htwt plot normal;
                    class gender;
                    probplot height;
               proc print data=htwt;
               run;
               ods pdf close;

Use ods csv or ods html in conjunction with the print procedure to export SAS datasets
               ods csv file='htwt.csv';
               proc print data=csv;
               run;
               ods csv close;


  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
               ods output BinomialProp=PropCI;
               proc freq data=htwt;
                     tables gender/bin;
               proc print data=PropCI;
               run;

               ods output basicmeasures=measure;
               proc univariate data=htwt;
               var weight;
               run;
               proc print data=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=1 to 10;
                  a = ranuni(0);
                  put a 5.2;
               end;
               run;
2. 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
           ;
           proc export data=one outfile='C:\Documents and
           Settings\anna\Desktop\MyDesktop\597.F10\one.csv';
                 run;
3. Writing SAS datasets to a delimited file or PC file with the export wizard

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:7
posted:12/30/2010
language:English
pages:4