SAS Institute. The Power to Know

FOCUS AREAS

Return to ODS Packages

Base SAS

ODS PACKAGE Statement

The ODS PACKAGE statement opens, adds to, publishes, or closes one SAS Output Delivery System (ODS) package object. The ODS PACKAGE statement is scheduled for production in SAS 9.2.


Syntax

The syntax for the ODS PACKAGE statement is as follows:

ODS PACKAGE<(name)> OPEN <options>;

ODS PACKAGE<(name)> ADD FILE="file-specification" | DATA=member-specification
          MIMETYPE="string" <PATH="path-specification"> <options>;

ODS PACKAGE<(name)> PUBLISH transport
         PROPERTIES(transport-property-1="value-1". . . transport-property-n="value-n");

ODS PACKAGE<(name)> CLOSE <CLEAR>;


Package Name

You can name a package by putting the name in parenthesis directly after PACKAGE in the statement:

ODS PACKAGE<(name)>;

A name is optional. A name enables more than one package to be open at a time. Each destination can connect with any package it wishes by specifying the package name in the same way.


Actions and Their Arguments

Actions include the following:

OPEN
creates the ODS package object that the ODS destinations can connect to. The ODS package object holds the package metadata and tracks the locations of any files that are added.

Here's an example:

  ods package open abstract="this is my abstract"
      description="this is my description";

The options for ODS PACKAGE OPEN statement are basically the metadata for the package:

Description=value
Specifies a string for the description for the package or file.

Abstract=value
Specifies a string for the abstract of the package or file.

NameValue="<name-1="value-1" . . . name-n="value-n">"
Specifies a string of name/value pairs for the name/value metadata on the package or file.

Template=value
Specifies the name of a package template to use.

ADD
adds a file or data set to the package using the specified mime type.

See the options for ODS PACKAGE OPEN. You can use Description=, Abstract=, NameValue=, or Template= to specify the metadata for the file or data set that you add.

FILE="file-specification" | DATA=member-specification
FILE="file-specification"
can be a fileref or a pathname for the file that you add.

DATA=member-specification
can be in the form libname.membername or membername for the data set that you add.

MIMETYPE="string"

PATH="path-specification"
optionally places the file or data set at the specified pathname within the package.

Here's an example:

  ods package add file="test.sas" mimetype="text/plain" path="sas/";

PUBLISH
builds the package and sends it to the chosen delivery transport.

For information about transport properties and their values, see SAS Integration Technologies Developer's Guide. You can supply more than one property.

Transports on the PACKAGE statement include the following. Notice that two of the transports (EMAIL and QUEUE) take an additional argument.

ARCHIVE PROPERTIES(transport-property-1="value-1" . . . transport-property-n="value-n")

publishes a package to an archive. Here's an example:
  ods package publish archive
      properties(archive_path="./" archive_name="test.spk");

EMAIL PROPERTIES(transport-property-1="value-1" . . . transport-property-n="value-n")
          ADDRESSES("e-mail-address-1" . . . "e-mail-address-n")

publishes a package to one or more e-mail addresses. Here's an example:
  ods package publish email
      addresses("eric.gebhart@sas.com" "saseag@sas.com")
      properties(archive_name="testPackage" archive_path="./");
QUEUE PROPERTIES(transport-property-1="value-1" . . . transport-property-n="value-n")
          QUEUES("queue-1" . . . "queue-n")

publishes a package to one or more message queues.

SUBSCRIBERS PROPERTIES(transport-property-1="value-1" . . . transport-property-n="value-n")

publishes a package to subscribers who are associated with the specified channel.

WEBDAV PROPERTIES(transport-property-1="value-1" . . . transport-property-n="value-n")

publishes a package to a WebDAV-compliant server.

CLOSE
deletes the package object and cleans up. As long as a package has not been closed, it can be published as many ways and times as desired. CLOSE has one, optional, argument:

CLEAR
specifies that all files that were automatically added to the package will be removed from where ODS wrote them.

Here's an example:

  ods package close clear;


Example: Creating a Package

This example demonstrates the arguments for the ADD action.

  ods package add file="test.sas" mimetype="text/plain" path="sas/";
  /* Make a fileref */
  %filename (t, t20, sas);

  ods package open;

  /* Add this program and put it in the sas directory */
  ods package add file="t20.sas" path="sas" mimetype="text/plain";

  /* Add this program as a fileref in root directory of package */
  ods package add file=t;

  /* Add a data set from a named library */
  ods package add data=sashelp.class;

  /* Create a temporary data set in the default library (Work) */
  proc sort data=sashelp.class out=foo;
       by age;
  run;

  /* Add a data set from the default library (Work) */
  ods package add data=foo;

  /* Create the archive */
  ods package publish archive properties(archive_name="t20.spk"
                                         archive_path="./");

  /* Delete the ods package object */
  ods package close;


Example: Using a Package

This is a simple example of using a package with ODS with the default, unnamed package. The destination must specify a package option to connect with the package.

  ods package open;

  ods html package file="test_1.html" newfile=output;
      options obs=6;

  proc sort data=sashelp.class out=foo;
    by age;
  run;

  proc print ;
    by age;
  run;

  ods html close;

  ods package add file="test.sas" mimetype="text/plain" path="SAS";

  ods package publish archive properties(archive_name="test.spk" archive_path="./");

  ods package close clear;

The package created by the above example code looks like this:

  unzip -l test.spk
  Archive:  test.spk
    Length     Date   Time    Name
   --------    ----   ----    ----
         25  08-08-06 21:02   PackageMetaData
        126  08-08-06 21:02   SAS/test.sas
      24966  08-08-06 21:02   test_6.html
      25494  08-08-06 21:02   test_5.html
      25492  08-08-06 21:02   test_4.html
      25310  08-08-06 21:02   test_3.html
      25669  08-08-06 21:02   test_2.html
      25158  08-08-06 21:02   test_1.html
   --------                   -------
     152240                   8 files


Example: Using Multiple Packages and Destinations

A more complex example with named packages and multiple destinations looks like this:

  ods listing close;
  goptions dev=gif xpixels=480 ypixels=320;

  ods package open;
  ods package(foo) open;

  ods rtf package file="test2.rtf";
  ods html package(foo) file="test2_1.html" newfile=output;

  *options obs=5;

  proc sort data=sashelp.class out=foo;
    by age;
  run;

  proc print ;
    by age;
  run;

  proc gplot data=sashelp.class;
    plot height*weight;
    by name;
  run;
  quit;

  ods html close;

  ods package add file="test2.sas" mimetype="text/plain" path="SAS";
  ods package(foo) add file="test2.sas" mimetype="text/plain" path="SAS";

  ods package publish archive properties(archive_name="testRTF.spk" archive_path="./");
  ods package(foo) publish archive properties(archive_name="testHTML.spk" archive_path="./");

  ods package(foo) close clear;
  ods package close clear;

The two archives the example code publish look like this:

  unzip -l testHTML.spk

  Archive:  testHTML.spk
    Length     Date   Time    Name
   --------    ----   ----    ----
         25  08-08-06 21:19   PackageMetaData
       1004  08-08-06 21:19   SAS/test2.sas
       3009  08-08-06 21:19   gplot18.gif
      24103  08-08-06 21:19   test2_25.html
       2998  08-08-06 21:19   gplot17.gif
      24095  08-08-06 21:19   test2_24.html
       3002  08-08-06 21:19   gplot16.gif
      24095  08-08-06 21:19   test2_23.html
       3014  08-08-06 21:19   gplot15.gif
      24095  08-08-06 21:19   test2_22.html
       2983  08-08-06 21:19   gplot14.gif
      24095  08-08-06 21:19   test2_21.html
       2997  08-08-06 21:19   gplot13.gif
      24095  08-08-06 21:19   test2_20.html
       2986  08-08-06 21:19   gplot12.gif
      24095  08-08-06 21:19   test2_19.html
       2979  08-08-06 21:19   gplot11.gif
      24095  08-08-06 21:19   test2_18.html
       2990  08-08-06 21:19   gplot10.gif
      24095  08-08-06 21:19   test2_17.html
       2986  08-08-06 21:19   gplot9.gif
      24094  08-08-06 21:19   test2_16.html
       3002  08-08-06 21:19   gplot8.gif
      24094  08-08-06 21:19   test2_15.html
       2991  08-08-06 21:19   gplot7.gif
      24094  08-08-06 21:19   test2_14.html
       2988  08-08-06 21:19   gplot6.gif
      24094  08-08-06 21:19   test2_13.html
       2966  08-08-06 21:19   gplot5.gif
      24094  08-08-06 21:19   test2_12.html
       3001  08-08-06 21:19   gplot4.gif
      24094  08-08-06 21:19   test2_11.html
       2995  08-08-06 21:19   gplot3.gif
      24093  08-08-06 21:19   test2_10.html
       3008  08-08-06 21:19   gplot2.gif
      24093  08-08-06 21:19   test2_9.html
       2972  08-08-06 21:19   gplot1.gif
      24093  08-08-06 21:19   test2_8.html
       2981  08-08-06 21:19   gplot.gif
      24114  08-08-06 21:19   test2_7.html
      24966  08-08-06 21:19   test2_6.html
      25494  08-08-06 21:19   test2_5.html
      25492  08-08-06 21:19   test2_4.html
      25310  08-08-06 21:19   test2_3.html
      25669  08-08-06 21:19   test2_2.html
      25158  08-08-06 21:19   test2_1.html
   --------                   -------
     667786                   46 files


  unzip -l testRTF.spk

  Archive:  testRTF.spk
    Length     Date   Time    Name
   --------    ----   ----    ----
         25  08-08-06 21:19   PackageMetaData
       1004  08-08-06 21:19   SAS/test2.sas
     164261  08-08-06 21:19   test2.rtf
   --------                   -------
     165290                   3 files