Mindmajix

Creating and Registering a SAS Stored Process

Creating a Stored Process

Beginning with version 3, SAS Enterprise Guide is the preferred method for working with stored processes because it provides the ability to create, register, and test stored processes from one interface.

 SAS ETL Studio also provides a point-and-click interface for creating and registering stored processes.

Stored processes must be .sas file (or PDS members on z/OS) in SAS®9.

       If you want to execute an SCL or SOURCE catalog entry, you must write a wrapper.sas program that uses PROC DISPLAY or %include to execute the entry. The SCL list of parameter values familiar to SAS/IntrNet SCL developers is not created automatically when using PROC DISPLAY, so you must use GLOBAL macro variables to access input parameters.

Stored processes can be created and registered manually by

  • writing the code in the SAS Windowing Environment (SAS Display Manager), or a text editor
  • creating the metadata describing the stored process using the SAS Management Console.

Manually Creating a Stored Process

There are three basic steps for manually creating a stored process:

Step 1 – Start with an existing, tested SAS program.

Step 2 – Add the stored process macros.

Step 3 – Register the stored process.

Step1: The SAS Program

Before creating a stored process, make sure that the SAS program it is based on is tested thoroughly.

If the program accesses a SAS data library with a hard-coded path, the MLE (Metadata Libname Engine) can be used to specify the LIBNAME statement if the library is registered in the metadata repository.

So

Screenshot_1431

would become:

Screenshot_1432

When you assign a libref in your metadata, using the LIBNAME statement, there is an advanced option that allows you to identify that the library is preassigned. If you select that option, you can leave the LIBNAME statement out all together, as long as the stored process server has the METAAUTOINIT option specified as an object spawner parameter. The default is set to NOMETAAUTOINIT.

METAAUTOINIT Specifies whether the IOM server should connect back to the SAS Metadata Server during startup in order to obtain additional configuration information such as object server parameters and preassigned libraries. When METAAUTOINIT is specified, the server uses the provided META* options to connect to the SAS Metadata Server. With NOMETAAUTOINIT, IOM server startup does not connect back to the SAS Metadata Server.

Step2: The Stored Process Macros

  • Use the %GLOBAL statement to identify any macro variables used in the original program. These macro variables will be removed and used as stored process input parameters.
  • The program continues with a standard comment (*ProcessBody;) that initiates input parameter processing, if any exist.
  • The %STPBEGIN and %STPEND macros provide the environment needed for a SAS program to run as  a stored process.
  • The %STPBEGIN macro initializes the Output Delivery
  • System (ODS) to generate output from the Stored Process.
  • The %STPEND macro terminates ODS processing and completes delivery of the output to the client or other destinations. The macros must be used as a matched pair.

Parameters are initialized differently for the stored process server and the workspace server. The stored process server sets parameter values before the stored process begins to execute. This means the first line of code in the stored process can access any input parameter macro variable. The workspace server does not set input parameters into macro variables until it reaches a comment line in the stored process.

A stored process that does not contain the comment line will never receive input parameters when executed on a workspace server.

It is recommended that you begin all stored processes (regardless of the server types) with %global declarations for all of your input parameters, followed by the *ProcessBody; comment.

Step3: Registering the Stored Process

The Stored Process Manager Plug-In in SAS Management Console, is used to provide the metadata to register the stored process.

Attributes include:

  • name, description, and keywords
  • location of the source code
  • server where the stored process will run
  • any input parameters
  • output options.

Creating and Registering a Stored Process

This demonstration shows how to manually create and register a stored process using an existing SAS program.

Screenshot_1433

  1. Start a SAS Display Manager session using Start Ð All Programs Ð SAS Ð BIArchitecture Ð Start SAS.

     This shortcut uses some of the same configuration files as your stored process server, so it provides a similar environment for testing. A benefit of this is that the Orion formats are already defined to this SAS session. If you invoke SAS outside of this environment, you receive format errors when you run this code.

 
   

      2. Copy the following program in to the Enhanced Editor and submit it.

Screenshot_1434

          The program above is stored in:

            c:\Workshop\winsas\sbiovr\customerlist.sas.

      3. Verify that there are no ERROR messages in the log and that the program produced the desired output.

 
   

      4. Update the program with the stored process macros and remove the %LET statement.

Screenshot_1435

      5. Select File Ð Save As and save the updated program to

C:\Workshop\winsas\sbiovr\StoredProcesses\customerlist.sas.

     The directory, StoredProcesses, does not exist and must be created.

Register the New Stored Process Program

       6. Start SAS Management Console by selecting Start Ð All Programs Ð SAS Ð SAS Management Console. Choose the BI Architecture metadata profile and username and password provided by the instructor.

Screenshot_1436

Screenshot_1437

      7. Locate the Stored Process Manager and select New Folder from the pop-up menu.

      The folder in the metadata repository is only a logical way to organize the stored process metadata. The physical programs are stored in a folder on the file system.

      8. Enter Training for the Name field and Stored Process  programs  for  the  SAS  9.1 training  course for the Description.

 
   

Screenshot_1438

SelectScreenshot_1252 to create the new folder.

 
   

Screenshot_1439

      9. Right-click the new folder Training and select New Stored Process.

      10. Specify Orion Customer  List for the Name field. Specify an appropriate description and keywords, if desired.

Screenshot_1440

Select Screenshot_1212

      11. Select Screenshot_1441to change the SAS Server to SASMain – Logical Stored Process Server.

       Make sure you change the SAS server to a stored process server. Stored processes can run on a workspace server, but this example needs the STP server because streaming results is the goal.

      12. Select Screenshot_1442to add a new Source Repository. This opens the Manage Source Repositories window.

Screenshot_1443

A Source Repository is not the same thing as a metadata repository. The Source Repository is the physical location where SAS programs are stored. You first need to allocate a storage location that your servers can access to hold your stored processes. This storage location, or repository, is implemented as a file system directory with the stored processes instances represented as files, by name, with a .sas extension if appropriate for the file system.

      13. SelectScreenshot_1388to open the Add Repository window.

      14. Specify C:\Workshop\winsas\sbiovr\StoredProcesses for the Location field and A directory for stored processes in the SAS 1 training class for the Description field.

Screenshot_1444

Select Screenshot_1207 to return to the Manage Source Repositories window.

Screenshot_1445

SelectScreenshot_1207 to return to the Manage Source Repositories window.

      15. SelectScreenshot_1441to change the Source repository to C:\Workshop\winsas\sbiovr\StoredProcesses.

      16. Type customerlist.sas for the Source file field.

      17. SelectScreenshot_1441to change the Output field to Streaming.

Screenshot_1446

SelectScreenshot_1212

Double-check the settings of this window carefully. It is easy to make a mistake in this window. If you misspell any of the names or choose the wrong options, your stored process will not work, and the problem can be hard to debug later.

      18. Select Screenshot_1388to add a parameter to the stored process.

      19. Set the following parameters:

          a. Specify Number of  Records for the Label field.

          b. Specify num for the SAS variable name field.

          c. Specify Number of  records to  print for the Description field.

          d. Select Required to make this a required parameter.

          e. Change the Type to Integer.

          F. Specify 20 for the Default value field.

Screenshot_1447

Select Screenshot_1207 to save the properties.

       The SAS variable name must match the name of the macro variable in the SAS program.

The new parameter for the number of records is displayed:

Screenshot_1448

          20. SelectScreenshot_1223

The new stored process is now visible in the Training

Screenshot_1449

 

 

 


 

0 Responses on Creating and Registering a SAS Stored Process"

Leave a Message

Your email address will not be published. Required fields are marked *

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.
Course Adviser

Fill your details, course adviser will reach you.