SAS Institute. The Power to Know

FOCUS AREAS

Return to ODS Packages

Base SAS

ODS Package Templates


Introduction

You can use an ODS package template with a package to provide information about metadata, publish properties, and internal paths, and specify whether to clear temporary files on close. ODS package templates are preproduction for SAS 9.2.

A package template defines how to create a package. It provides metadata for the package and all the controls to publish the package. A package template also defines paths to be created within the package. Each of the output files a destination can create can be directed to any path. Files can also be sorted into paths based on mimetypes. A package template gives the ability to create packages with structure.


Generating a List of Package Templates

Issue the following SAS statements to get a list of the package templates that you have:

  proc template;
  list packages;

By default, PROC TEMPLATE lists the packages in SASHELP.TMPLMST and SASUSER.TEMPLAT. Typically, SASHELP.TMPLMST is a read-only item store for the SAS packages, and SASUSER.TEMPLAT is the item store for user-defined packages.

Tip: To specify a user-defined package template that is stored in an item store other than SASUSER.TEMPLAT, assign the item store to the ODS search path with the ODS PATH statement.


Viewing the Source for a Package Template

To see the source for a package template, use PROC TEMPLATE and specify the two-level name of the package. For example, to see the source of the default package template, issue these SAS statements:
  proc template;
  source packages.default;


DEFINE PACKAGE Statement

The DEFINE PACKAGE statement, package attribute statements, and path statements together create a package definition. Many of these language elements are explained in more detail in the SAS online documentation; see the topic about using the TEMPLATE procedure to create markup language tagsets.


Syntax

The syntax is as follows:

DEFINE PACKAGE package-path </STORE=libref.template-store <(READ | WRITE | UPDATE)>>;
      <ABSTRACT="string";>
      <ARCHIVE_NAME="string";>
      <CLEAR=YES|NO;>
      <DEFAULT_PATH="string";>
      <DESCRIPTION="string";>
      <NAMEVALUE='name="value"...name-n="value-n" ';>
      NOTES 'text';
      <PATH 'path_string' FILES=value(s) MIME_TYPES=value(s);>
      <PUBLISH=(transport) PROPERTIES(property="value"...property-n="value-n");>
END;


Arguments for the DEFINE PACKAGE Statement

package-path
specifies where to store the package definition. A package path consists of one or more names, separated by periods. Each name represents a directory, or level, in a template store (item store). PROC TEMPLATE writes the definition to the first item store that you can write to in the current path. For example:
   define package packages.mypkg;

NOTE: You can use the ODS PATH statement to control the item store where the package definition will be stored. Optionally, you can use the /STORE= option to provide a specific item store name.

Tip: Names are not case sensitive. However, PROC TEMPLATE frequently uppercases the first letter to make things more readable.

/STORE=libref.template-store <(READ | WRITE | UPDATE)>;
specifies the template store in which to store the definition. If the template store does not exist, it is created. Specifying STORE= overrides the search list specified with the PATH statement. For example:
   define package packages.mypkg /store=sasuser.templat (update);
READ
provides read-only access.

WRITE
provides write access as well as read access. If the tagset does not exist, then WRITE access creates a new tagset. If the tagset does exist, then WRITE access will not replace an existing tagset.

UPDATE
provides update access as well as read access. If the tagset does not exist, then UPDATE will not create a new tagset. If the tagset does exist, then UPDATE will replace it.


Package Attributes

The following statements specify package attributes, path, and publish:

ABSTRACT="string";
defines the text that is used for the package abstract.

ARCHIVE_NAME="string";
gives the archive file name the package should be written to by default. This implies a publish transport of Archive. The options in an ODS PUBLISH statement can override this name and transport.

CLEAR=YES|NO;
specifies whether all automatically added files are cleared from the filesystem when the package is closed.

DEFAULT_PATH="string";
defines the default path to place files within the package.

DESCRIPTION="string";
defines the text that is used as the description for the package.

NAMEVALUE='name="value"...name-n="value-n" ';
defines the name/value metadata for the package. For example:
   NameValue='name="test" stuff="junk"';

NOTES 'text';
provides information about the tagset.


Package Statements

PATH 'path_string' <FILES=value...value-n MIME_TYPES=value...value-n> ;
defines the path that is used within the package for any file that matches the path's rules. A package can have multiple path definitions.

FILES= <BODY> <CONTENTS> <PAGES> <FRAME> <STYLESHEET> <CODE> <DATA>
specifies one or more of the seven different files that the ODS MARKUP destination is capable of creating. If the current file being added to the package is in the path's file list, that path is used when placing the file in the package. For example:
   files = body contents frame
MIME_TYPES=";value...value-n" ;
is a space-delimited string that lists the mimetypes. If a file's mimetype matches a mimetype for a path, then the file is placed at that path inside the package. For example:
   mime_types="image/gif image/jpeg image/bmp"
PUBLISH=(transport) PROPERTIES( property="value"...property-n="value-n");
define the default transport and properties to publish the package. Transports include the following:

Archive
WebDav
Queue
Subscribers
Email

The transports and the properties are documented in the SAS Integration Technologies Developer's Guide.

Here's an example:

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


Example: Package Template

The following example defines a tagset with assigned mime types, and a package template that describes how a package should be built.
  proc template;
     define tagset tagsets.test;
        parent=tagsets.html4;
        default_mimetype = "text/html";
        stylesheet_mimetype = "text/css";
     end;
  run;

  proc template;
     define package packages.test;

        /* publish info */
        /* where to publish to.  archive, webdav, queue, email, etc. */
        /* publish properties, key value pairs. */

        publish = Archive properties ( archive_path="./" archive_name="test" );

        Description = "This is my description";
        Abstract = "This is my abstract";

        /* clean up the temporary files */
        clear = yes;

        NameValue = 'path="./"';

        /* Paths.  Where to put stuff inside the package */

        default_path = "./";

        path './'
             files = body contents frame code data
             mimetypes = "text/html"
             ;

        path 'style/'
             mimetypes = "text/css";
             ;

        path 'style/'
              files = stylesheet
             ;

        path 'images/'
             mimetypes = "image/bmp image/gif image/jpg image/png"
             ;

        path 'drawing/'
             mimetypes = "image/svg+xml"
             ;

        path 'rtf/'
             mimetypes = "text/rtf text/richtext"
             ;
        end;

  run;

  /* list the packages, and source the one we just created */

  proc template;
     list packages;
  source packages.test;
  run;

  ods listing close;

  goptions dev=gif xpixels=480 ypixels=320;

  ods package open template=test namevalue = 'stuff="junk"';

  ods tagsets.test package file="t2.html" stylesheet="t2.css";

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

  ods tagsets.test close;

  /* add the test case to the package */
  ods package add file="t15.sas" path="sas" mimetype="text/plain";

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

  /* close the package and clean up */
  ods package close;

Test.spk is the package created by this program, and its contents looks like this:

  unzip -l test.spk
  Archive:  test.spk
    Length     Date   Time    Name
   --------    ----   ----    ----
         44  08-15-06 20:54   PackageMetaData
       1716  08-15-06 20:54   sas/t15.sas
       3003  08-15-06 20:54   images/gplot18.gif
       2991  08-15-06 20:54   images/gplot17.gif
       2995  08-15-06 20:54   images/gplot16.gif
       3006  08-15-06 20:54   images/gplot15.gif
       2976  08-15-06 20:54   images/gplot14.gif
       2998  08-15-06 20:54   images/gplot13.gif
       2979  08-15-06 20:54   images/gplot12.gif
       2968  08-15-06 20:54   images/gplot11.gif
       2983  08-15-06 20:54   images/gplot10.gif
       2979  08-15-06 20:54   images/gplot9.gif
       2981  08-15-06 20:54   images/gplot8.gif
       2986  08-15-06 20:54   images/gplot7.gif
       2973  08-15-06 20:54   images/gplot6.gif
       2958  08-15-06 20:54   images/gplot5.gif
       2992  08-15-06 20:54   images/gplot4.gif
       2980  08-15-06 20:54   images/gplot3.gif
       2998  08-15-06 20:54   images/gplot2.gif
       2965  08-15-06 20:54   images/gplot1.gif
       2973  08-15-06 20:54   images/gplot.gif
       5519  08-15-06 20:54   ./t2.html
      22869  08-15-06 20:54   style/t2.css
   --------                   -------
      85116                   23 files