Managing Universal Printers Using the PRTDEF Procedure

About Using the PRTDEF Procedure

Printer definitions can be created for an individual or for all SAS users at a site by using the PRTDEF procedure. The PRTDEF procedure can be used to do many of the same printer management activities that you can do with the Universal Printing windows. The PRTDEF procedure can be used in any execution mode, but it is especially useful if you use SAS in batch mode, where the Universal Printing windows are unavailable.
To define or modify one or more printers with the PRTDEF procedure, you first create a SAS data set that contains variables that correspond to printer attributes. These four variables must be specified for every printer destination:
DEST
specifies the printer destination.
DEVICE
specifies the device name.
MODEL
specifies the name of a printer prototype. For a list of printer prototypes, open the SAS registry to this key: \CORE\PRINTING\PROTOTYPES.
NAME
specifies the name of the printer.
For a list of optional variables, see Input Data Set: PRTDEF Procedure in Base SAS Procedures Guide. The PRTDEF procedure reads the data set and converts the variable attributes into one or more printer definitions in the SAS registry.
After you create the printer definition data set, you run the PRTDEF procedure to create the printer.
Only system administrators or others who have write permission to the Sashelp library can use the PRTDEF procedure to create printer definitions for all SAS users at a site. Individuals have write permission to their Sasuser library and can use the PRTDEF procedure to create their own printers. However, the printer definition is stored in the Sasuser library and is lost if the Sasuser library is deleted. Printer definitions that are created by individuals are available only when the directory where the printer definition is stored is specified as the Sasuser library. For information about assigning the Sasuser library, see SASUSER= System Option in SAS System Options: Reference.
For more information see, PRTDEF Procedure in Base SAS Procedures Guide.

Examples of Creating New Printers and Previewers Using the PRTDEF Procedure

Introduction

These examples show you how to use the PRTDEF procedure to define new printers and to manage your installed printers and previewers.
After a program statement containing the PRTDEF procedure runs successfully, the printers or previewers that have been defined appear in the Print Setup window. A complete set of all available printers and previewers appear in the Printer name list. Printer definitions can also be viewed in the Registry Editor window under CORE\PRINTING\PRINTERS.

Creating a Data Set That Defines Multiple Printers

When you create a data set to use with the PRTDEF procedure to define a printer, you must specify the name, model, device and, destination variables.
See the PRTDEF Procedure in Base SAS Procedures Guide in Base SAS Procedures Guide for the names of the optional variables that you can also use.
The following code creates a data set to use with the PRTDEF procedure:
data printers;
   input name $15. model $35. device $8. dest $14.;
   datalines;
Myprinter      PostScript Level 1 (Gray Scale)     PRINTER printer1
Laserjet       PCL 5 PCL 5e (RunLength)           PIPE    lp -dprinter5
Color LaserJet PostScript Level 2 (Color, Duplex) PIPE    lp -dprinter2
;
run;

proc print data=printers;
run;
Here is the output:
The Printer Data Set
The Printer Data Set
After you create the data set containing the variables, you run the PRTDEF procedure. The PRTDEF procedure creates the printers that are named in the data set by creating the appropriate entries in the SAS registry.
proc prtdef data=printers usesashelp replace;
run;
The USESASHELP option specifies that the printer definitions are to be placed in the Sashelp library, where they are available to all users. If the USESASHELP option is not specified, then the printer definitions are placed in the current Sasuser library, where they are available to the local user only, and the printers that are defined are available only in the local Sasuser directory. However, to use the USESASHELP option, you must have permission to write to the Sashelp library.
The REPLACE option specifies that the default operation is to modify existing printer definitions. Any printer name that already exists is modified by using the information in the printer attributes data set. Any printer name that does not exist is added.

Creating a Printer for Multiple Users

This example creates a Tektronix Phaser 780 printer definition that specifies to use Ghostview as the preview application and to store the printer definition in the Sashelp library. The bottom margin is set to two centimeters, the font size to 14 point, and the paper size to ISO A4.
data tek780;
   name = "Tek780";
   desc = "Test Lab Phaser 780P";
   model = "Tek Phaser 780 Plus";
   device = "PRINTER";
   dest = "testlab3";
   preview = "Ghostview";
   units = "cm";
   bottom = 2;
   fontsize = 14;
   papersiz = "ISO A4";
run;

proc prtdef data=tek780 usesashelp;
run;
Note: To preview output for this printer, you must create a Ghostview printer definition. You can do this either in the Preview Definition Wizard (Printer Properties Window Displaying Advanced Tab), on the Advanced tab of the Printer Properties window (Previewer Definition Window to Enter Command to Open Previewer Application) or by using the PRTDEF procedure.
Here is a Ghostview printer definition using the PRTDEF procedure:
data gsview;
name = "Ghostview";
desc = "Print Preview with Ghostview";
model= "Tek Phaser 780 Plus";
viewer = 'gv %s';
device = "dummy";
dest = " ";

proc prtdef data=gsview list replace usesashelp;
run;
The PROC PRTDEF statement LIST option specifies to write the printer definition to the log.
Note: You must specify a preview command either in the Preview Definition Wizard (Printer Properties Window Displaying Advanced Tab) or on the Advanced tab of the Printer Properties window (Previewer Definition Window to Enter Command to Open Previewer Application). An example of a preview command is ghostview -bg white -fg black -magstep -2 –nolabel %s
For more information about print previewers see, Creating PostScript Previewer Definitions.

Adding, Modifying, and Deleting Printers

This example uses the PRINTERS data set to add, modify, and delete printer definitions. See the PRTDEF Procedure in Base SAS Procedures Guide for more variables that you can use to define a printer. The following list describes the variables used in the example:
  • The MODEL variable specifies the printer prototype to use when defining this printer.
  • The DEVICE variable specifies the type of I/O device to use when sending output to the printer.
  • The DEST variable specifies the output destination for the printer.
  • The OPCODE variable specifies what action (Add, Delete, or Modify) to perform on the printer definition.
  • The first Add operation creates a new printer definition for Color PostScript in the registry and the second Add operation creates a new printer definition for ColorPS in the registry.
  • The Mod operation modifies the existing printer definition for LaserJet 5 in the registry.
  • The Del operation deletes the printer definitions for printers named “Gray PostScript” and “test” from the registry.
The following example creates a printer definition in the Sashelp library. Because the definition is in Sashelp, the definition becomes available to all users. Special system administration privileges are required to write to the Sashelp library. An individual user can create a personal printer definition by specifying the Sasuser library instead.
data printers;
   infile datalines dlm='#';
   length name $ 80
   model $ 80
   device $ 8
   dest $ 80
   opcode $ 3;
   input opcode $ name $ model $ device $ dest $ ;
datalines;
add#  Color PostScript F2#  PostScript Level 2 (Color)#      DISK#  sasprt.ps
mod#  LaserJet 5#           PCL 5c (DeltaRow)#               DISK#  sasprt.pcl
del#  Gray PostScript#      PostScript Level 2(Gray Scale)#  DISK#  sasprt.ps
del#  test#                 PostScript Level 2 (Color)#      DISK#  sasprt.ps
add#  ColorPS#              PostScript Level 2 (Color)#      DISK#  sasprt.ps
;

proc prtdef data=printers list;
run;
Note: If the end user modifies and saves new attributes for an administrator-defined printer in the Sashelp library, the printer becomes a user-defined printer in the Sasuser library. Values that are specified by the user override the values that were set by the administrator. If the user-defined printer definition is deleted, the administrator-defined printer reappears.

Creating PostScript Previewer Definitions

These examples show how to create the Adobe Acrobat Reader print previewer and the Ghostview print previewer in order to preview PDF output in both formats. The variables in the data sets have values that the PRTDEF procedure uses to produce the print previewer definition in the SAS registry.
  • The NAME variable specifies the printer name that is associated with the rest of the attributes in the printer definition data record.
  • The DESC variable specifies the description of the printer.
  • The MODEL variable specifies the printer prototype to use when defining this printer.
  • The VIEWER variable specifies the host system commands for print preview.
    Note: The ghostview %s command needs to be the fully qualified command if it is not in the machine's command path.
    Note: You must specify a preview command either in the Preview Definition Wizard (Printer Properties Window Displaying Advanced Tab) or on the Advanced tab of the Printer Properties window (Previewer Definition Window to Enter Command to Open Previewer Application). An example of a preview command is ghostview -bg white -fg black -magstep -2 –nolabel %s and c:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe' %s.pdf.
  • The DEVICE variable should always be DUMMY.
  • DEST should be blank to specify that output is not returned.
The following program creates a print previewer definition for using Adobe Acrobat Reader:
data adobeR;
   name = "myAdobeReader";
   desc = "Adobe Reader Print Preview";
   model= "PDF Version 1.2";
   viewer = "'c:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe' %s.pdf";
   device = "dummy";
   dest = " ";
run; 
proc prtdef data=adobeR list replace;
run;
The following program creates a print previewer definition for using Ghostview:
data gsview;
   name = "MyGhostview";
   desc = "Print Preview with Ghostview";
   model= "PostScript Level 2 (Color)";
   viewer = 'ghostview %s';
   device = "dummy";
   dest = " ";
run; 
proc prtdef data=gsview list replace;
run;

Exporting and Backing Up Printer Definitions

The PRTEXP procedure enables you to back up your printer definitions as a SAS data set that can be restored with the PRTDEF procedure.
The PRTEXP procedure has the following syntax.
PROC PRTEXP <USESASHELP> <OUT=dataset>
   <SELECT | EXCLUDE> printer_1 printer_2 ... printer_n;
The following example shows how to back up four printer definitions (named PDF, postscript, PCL5, and PCL5c) using the PRTEXP procedure:
proc prtexp out=printers;
   select PDF postscript PCL5 PCL5c;
run;
For more information, see PRTEXP Procedure in Base SAS Procedures Guide.

Sample Values for the Device Type, Destination, and Host Options Fields

The following list provides examples of the printer values for device type, destination, and host options. Because these values can be dependent on each other, and the values can vary by operating environment, several examples are shown. You might want to refer to this list when you are installing a printer or when you change the destination of your output.
  • Device Type: Printer
    • z/OS
      • Device type: Printer
      • Destination: (leave blank)
      • Host options: sysout=class-value dest=printer-name
    • UNIX and Windows
      • Device type: Printer
      • Destination: printer name
      • Host options: (leave blank)
  • Device Type: Pipe
    Note: A sample command to send output to an lp-defined printer queue on a UNIX host is lp -ddest
    • UNIX
      • Device Type: Pipe
      • Destination: command
      • Host options: (leave blank)
  • Device Type: FTP
    Note: An example of a node name is pepper.unx
    • z/OS
      • Device type: FTP
      • Destination: ftp.out
      • Host options: host='nodename' recfm=vb prompt
      • Device type: Printer
      • Destination: printer name
      • Host options: (leave blank)
    • Windows
      • Device type: FTP
      • Destination: ftp.out
      • Host options: host='nodename' prompt
    • UNIX
      • Device type: FTP
      • Destination: filename.ext
      • Host options: host='nodename' prompt
  • Device Type: Socket
    Note: An example of an lp destination queue is lp286nc0.prt:9100
    • UNIX
      • Device type: Socket
      • Destination: destination-queue
      • Host options: (leave blank)