The PACKAGE Statement

SAS/IML 14.1 introduced support for packages. A package consists of SAS/IML source code, documentation, data sets, and sample programs. Packages are a convenient way for programmers to download and install functions that extend the functionality of SAS/IML software. You can find the documentation for the package functionality in the SAS/IML User's Guide in the chapter Packages.

The IML procedure and IMLPlus provide very similar support for packages. There are, however, a few differences you should be aware of.

Package Installation

IMLPlus and the IML procedure maintain separate sets of installed packages. The package collections maintained by IMLPlus are separate from the package collections maintained by the IML procedure. This is because IMLPlus installs packages on the client computer while the IML procedure installs packages on the SAS server. In summary,

Package Collection Directories

The IML procedure uses three SAS system options to locate the package collections.

Collection SAS Option Default Value on Windows
Private IMLPACKAGEPRIVATE <MyDocuments>\My SAS Files\IML\Packages
Public IMLPACKAGEPUBLIC C:\ProgramData\SAS\IML\Packages
System IMLPACKAGESYSTEM <SASHome>\SASFoundation\9.4\iml\sasmisc\packages

IMLPlus does not use these SAS system options. Instead, IMLPlus uses the following directories:

Collection Directory
Private <PersonalFilesDirectory>\Packages
Public C:\ProgramData\SAS\IML Studio\Packages
System <SASHome>\SASIMLStudio\14.2\Packages

The notation <PersonalFilesDirectory> refers to the Personal Files Directory. The default location of the Personal Files Directory is:

C:\Users\userid\Documents\My IML Studio Files

The notation <SASHome> refers to the directory in which SAS is installed. By default, <SASHome> is

C:\Program Files\SASHome

Note that the directory C:\ProgramData is hidden. To view this directory in Windows, you must enable the display of hidden files and folders.

The PACKAGE INSTALL Statement

The IML procedure supports the use of a fileref to specify the ZIP file for the PACKAGE INSTALL statement. For example:

filename packzip "C:\My Packages\Example.zip";
package install packzip;

IMLPlus does not support the use of a fileref with the PACKAGE INSTALL statement because IMLPlus installs packages on the client computer and not on the SAS server (where filerefs are processed).

The PACKAGE LIBNAME Statement

The PACKAGE LIBNAME statement defines a libref that refers to the data subdirectory of a package. While the syntax of the PACKAGE LIBNAME statement is the same in IMLPlus as in the IML procedure, the actions performed internally by IMLPlus are more extensive.

The IML procedure installs packages on the SAS server. Therefore, a package's data subdirectory resides on the SAS server and SAS can access the data sets in a straightforward manner. IMLPlus installs packages on the client computer. Therefore, a package's data subdirectory resides on the client computer. A libref cannot refer to a directory on the client computer. To enable SAS to access a package's data files, the PACKAGE LIBNAME statement in IMLPlus copies the package's data subdirectory to a temporary directory on the SAS server and then assigns the libref to that temporary directory. If subsequent statement processing modifies a data set within the library, that modification will not affect the original copy of the data set on the client computer.

You can see this temporary directory mechanism in action by using the PATHNAME function, as shown in the following program:

package load AboveBelow;
package libname PACKDATA AboveBelow;
print (pathname("PACKDATA"));
The PACKAGE HELP Statement

A package can provide help in three different formats: PDF, HTML, and text. IMLPlus supports all three formats whereas the IML procedure only supports the text format. When IMLPlus executes a PACKAGE HELP statement, it uses the following logic to determine which help format to display:

  1. If the package's help subdirectory contains a file named PackageName.pdf, IMLPlus displays that PDF file.
  2. If the package's help subdirectory contains a file named index.html or index.htm, IMLPlus displays that HTML file.
  3. If the package's help subdirectory contains a file named PackageName.txt, IMLPlus displays that text file.
  4. Otherwise, IMLPlus displays an error message.
Program Processing Phases

The PACKAGE statement supports various commands. In IMLPlus, the LOAD command operates during the parse phase of program processing and all the other commands operate, by default, during the runtime phase. The reason the LOAD command operates during the parse phase is because the usual purpose of loading a package is to define the package's modules. If the LOAD command operated during the runtime phase, IMLPlus would not be able to resolve calls to the package's modules during the link phase.

The following table shows the PACKAGE statement commands and the phase of program processing in which they operate:

PACKAGE Statement Command Phase of Operation
HELP Run time
INFO Run time
INSTALL Either (default is run time)
LIBNAME Run time
LIST Run time
LOAD Parse time
UNINSTALL Either (default is run time)

By default, the INSTALL and UNINSTALL commands operate during the runtime phase of program processing. However, by using the PARSETIME option you can instruct the commands to operate during the parse phase:

package uninstall MyPackage(PARSETIME NOWARN);
package install "C:\My Packages\MyPackage.zip"(PARSETIME);
package load MyPackage;
run MyPackageSub1( 1 );

For this program, IMLPlus performs the following operations during the parse phase of program processing:

Then, during the runtime phase of program processing, IMLPlus performs the following operations:

If you did not use the PARSETIME option, IMLPlus would issue an error when it processed the PACKAGE LOAD statement because the package would not be installed. This is because IMLPlus processes the PACKAGE LOAD statement during the parse phase but it processes the PACKAGE INSTALL statement, by default, during the runtime phase.

It is important to understand that during the parse phase of program processing no variables exist and control flow statements are not followed. As an example, the following statements do not have the intended consequence:

if x = 1 then
    package load Pack1;
else
    package load Pack2;

These statements are processed by IMLPlus as if they were written as follows:

package load Pack1;
package load Pack2;
if x = 1 then
    ;
else
    ;

You can use the PARSETIME option in programs that you intend to run with the IML procedure. The IML procedure ignores the PARSETIME option because it is not relevant to that environment.