NESUG 2006 Applications

Submitting Mainframe Batch Jobs from PC SAS® Rick Andrews, Centers for Medicare and Medicaid Services, Baltimore, MD

ABSTRACT

The SAS System offers a host of mechanisms to interact with remote platforms. This paper discuss’ an application to submit IBM® Mainframe batch jobs from a Microsoft® Windows™ using SAS/AF®, SAS/Connect®, and the Internal Reader. These tools can create applications that keep track of each , log, and output and send email when all is complete. This provides avenues for individuals without experience on the “Big Iron” (mainframe) to submit programs with little to no knowledge of IBM’s Language (JCL) or Computer Associate’s (CA) Interactive System Productivity Facility (ISPF). The code shown below was created using version 8.2 of SAS.

INTRODUCTION CONTENTS

From a user’s perspective, the IBM Mainframe has remained relatively • SAS/AF the same for many years, though newcomers often find learning ISPF • CATALOGS either daunting or archaic. With so many processes and applications • FRAME ENTRIES migrating to Windows and platforms, recent college graduates are • COMPONENTS unacquainted with maneuvering “Big Blue” (mainframe) because most • PROPERTIES courses are related to the newer operating environments. • BUILD FRAME

• PUSH BUTTON CONTROLS The SAS System helps bridge the gap between these new worlds and the old, by way of its application facility called SAS/AF. This robust • SAS COMPONENT LANGUAGE resource offers an object oriented approach that many are unaware even • LABELED SECTIONS exists. The SAS Component Language (SCL) contains many powerful • SUBMIT BLOCKS functions to help build user-friendly front end systems. SAS/Connect is • SAS/CONNECT the channel allowing the link between a Personal Computer (PC) and the • REMOTE SUBMIT powerful “Old Giant”. The Internal Reader is a special program, which • JOB acts like a spawner process for submitting mainframe batch jobs. • INTERNAL READER

SAS/AF

SAS/AF software provides a set of tools allowing for the creation of applications. It provides interactive interfaces to all of the analysis, presentation, data access and management features of SAS.

These applications are stored in SAS catalogs in the form of FRAME entries, which provide visual, object-oriented components for computer environments supporting a graphical user interface (GUI). PROGRAM and MENU entries provide character-based features for systems where a GUI is not available. The SAS Component Language (SCL) entries are for object-oriented programs that interact with Frames. The CBT and HELP entries provide information and assistance to users.

This paper will discuss the very basics of creating a PC SAS batch application for submitting mainframe batch jobs. Due to space limitations only an overview of FRAME and SCL entries and the SAS code necessary will be provided. An example application can be downloaded from the website listed in the References section at the end of the paper. Varying mainframe configurations will demand modifications as necessary.

1 NESUG 2006 Applications

CATALOG

SAS catalogs are special SAS files that store many different kinds of information in smaller units called catalog entries. A single SAS catalog may contain several different types of catalog entries. They can hold application information such as window definitions, formats, informats, macros, or graphics output.

1. Submit a Libname statement in a Program Editor pointing to the Windows folder housing the SAS catalog.

2. Click on the “Sasbatch” folder in the SAS Explorer Library

3. Click on File, New, Catalog, and name the catalog “Batchcat”

4. Click on File, New, Frame

5. Save the untitled frame as “Batch_submit”

FRAME ENTRY

The Frame entry (or class) is the foundation for graphical SAS applications. The Frame class provides windowing capabilities to all SAS/AF applications and serves as a container for visual controls and non- visual components that create the user interface. The Frame class (or entry) enables the creation of windows and dialog boxes, menu bars or banners, and application help.

The SAS/AF development environment consists of four primary windows:

- Frame Build Mode is where the GUI is designed - Component window lists available SAS/AF components - Property window is for assigning component attributes - Source window is for writing and compiling SCL code

A Frame entry can be opened in Build Mode by double-clicking on the item from the SAS Explorer window.

2 NESUG 2006 Applications

COMPONENTS

When a Frame entry is open in build mode the Components window displays the objects available to the Frame. These objects are called components. There are two types of components:

Controls are visible items on the Frame. These are objects which comprise the GUI. They are represented by an icon in color within the Components window.

Models are components not visible on the Frame. They are used to describe data, usually for display by a Control component and are represented by black-and-white icons.

PROPERTIES

The Properties window provides the ability to assign values to component properties via a selection list or push button at build time of the Frame. The Properties window has two parts:

The Properties drill-down tree on the left displays both visual and non-visual components currently on the Frame, as well as the Frame component itself.

The Attributes data table displaying the selected component’s properties is on the right hand side of the Components window. This is where values can be modified.

BUILD FRAME

Open the SAS Explorer and double-click on the Sasbatch library, the Batchcat catalog, and the Batch_submit Frame created earlier. The BUILD procedure can also be used as shown below:

1) proc build catalog=sasbatch.batchcat.batch_submit.frame; run; 2) With the Build window active, click on the Components window button 3) Scroll down to the Text Entry Control and drag it onto the Batch_submit Frame entry. 4) With the Text Entry selected, click on the Properties window button

5) Change the Value of the “name” Attribute to: txt_SasProg

Properties Attributes

3 NESUG 2006 Applications

PUSH BUTTON CONTROLS

1) Drag the Push Button Control onto the Batch_submit Frame entry 2) Change the “label” Attribute in the Properties window to “Choose Program” 3) Change the “name” Attribute in the Properties window to “SELECT”

SUBMIT BUTTON

1) Drag another Push Button Control onto the Batch_submit Frame entry 2) Change the “label” Attribute in the Properties window to “Submit” 3) Change the “name” Attribute in the Properties window to “SUBMITPGM” 4) Save and save often!-)

SAS COMPONENT LANGUAGE

SCL is a programming language enabling the development of computing applications, from simple programs accomplishing a few tasks to sophisticated, interactive applications using procedures available from other SAS products. The software can create data entry applications displaying tables and menus or sort, merge, manipulate, quantify and communicate tables, charts, graphs, and maps.

In earlier releases of SAS software, SCL was called Screen Control Language. Version 7 introduced several new features enabling the design of object-oriented applications. The new name, SAS Component Language, reflects the object-oriented capabilities of the new SCL.

SCL programs execute in phases, such as the initialization phase and the termination phase. During each phase, control of the entry can pass to a different segment of an SCL program. The segments of the program are identified by labels; that is, the SCL program is divided into Labeled Sections.

INIT: ... SCL STATEMENTS ... RETURN;

TERM: ... SCL STATEMENTS ... RETURN;

Labeled Sections are program segments that are designed to be called only within the program in which they are defined. They begin with a label and end with a RETURN statement. A label may be one of the reserved labels such as INIT or TERM; it may correspond to a field name, window-variable name, or object name in the application; or it may simply identify a module that is called repetitively, such as a module that sorts data (SAS, 1999).

4 NESUG 2006 Applications

RESERVED LABELS

INIT: The INIT section is executed before the application window is displayed and is used to initialize variables, import values through variables, or open tables.

MAIN: The MAIN section is executed each time the user modifies a field in the window and presses ENTER.

TERM: The TERM section is executed when the END command is issued. The TERM section might be used to close tables, export values of macro variables, or construct execution statements.

CREATE SCL ENTRY

1) Open the Batch_submit Frame 2) Click on the SCL button

Opening the SCL entry from the Frame ensures the two entries are “linked” together.

SCL PROGRAM

The SCL BUILD window looks and acts very much like the SAS Program Editor, though has its own unique vocabulary and syntax. An SCL program consists of one or more SCL statements including keywords, expressions, constants, and operators.

The reserved label, INIT, is an example of a keyword, as described above. SCL is the controlling language in a SAS/AF application. When submission of other SAS products is required, the keywords SUBMIT and CONTINUE are used to signify the beginning of SAS procedures and syntax.

*------*; * Initialize SCL Variables *; The INIT section here is designed to ensure the SAS/AF *------*; window is “zoomed” to its full measure and sets the SCL INIT: variable “txt_SasProg” with a property of “text” and sets

*** Maximize the window ***; its initial value to “Click on the Choose Program button.” call execcmd('ZOOM ON');

*** Populate text box with initial value ***; txt_SasProg.text = "Click on the Choose Program button.";

RETURN;

*------*; * Select PC File to Submit *; The SELECT section is linked by way of its name to the *------*; “Choose Program” button. It uses the FILEDIALOG SELECT: function to return the name of the selected program to the text box on the Frame. *** Open File Dialog box to choose program ***; rc=filedialog('open',selfile,'','/sas','*.sas'); Note that SCL is very different than traditional SAS code *** Set value of text box to selected file ***; and has its own syntax. It is executed within a labeled txt_SasProg.text = selfile; section as described above. The INIT and SELECT sections shown here are examples of labeled sections. RETURN;

5 NESUG 2006 Applications

=

*------*; * Submit the Selected Program *; The SUBMITPGM section is linked by *------*; way of its name to the “Submit” button SUBMITPGM: created earlier.

*** Set SCL variable to value of txt_SasProg from Frame ***; SasProg = txt_SasProg.text; An SCL variable called SasProg is set to the txt_SasProg.text va lue held in the text *** Verify that a value exists in the txt_SasProg field ***; box of the Frame. if txt_SasProg.text = " " or txt_SasProg.text = "You must Choose a Program!" Error handling code is written to verify a or txt_SasProg.text = "Click on the Choose Program button." program has indeed been selected. If the then do; txt_SasProg.text = "You must Choose a Program!"; value of txt_SasProg.text is blank or set RETURN; to a certain value, control will RETURN to end; the Frame.

SUBMIT CONTINUE

As previously mentioned, SCL has its own vocabulary and syntax. When the submission of traditional Base SAS code is

desired the SUBMIT command with the CONTINUE option is used to execute the SAS code within the current submit block. Execution of the SCL program continues with the statement that follows the ENDSUBMIT command.

Example: INIT: SCL Code CALL EXECCMD('ZOOM ON');

SUBMIT CONTINUE; SAS Code PROC “lottery“ DATA=lotto_numbers OUT=winning_ticket; RUN; ENDSUBMIT; K Wishful thinking 8-) RETURN;

*** Submit Base SAS Statements ***; SAS/CONNECT

SUBMIT CONTINUE; This software is the SAS-to-SAS client/server toolset providing management, access, and data *------*; processing within a dist ributed environment (SAS * SIGNON to Mainframe *; 1999). The SIGNON to Mainframe shown here is *------*; %let rmthost=mainframe; an example of the code required to create the options remote=rmthost comamid=tcp device=win; connection between a Personal Computer and signon rmthost user=_prompt_ ; IBM Mainframe. The software must be configured by the SAS administrator beforehand. *------*; * Set up Message Box via Windows API *; *------*; Windows API filename sascbtbl temp;

data _null_; The Application Programming Interface (API) was file sascbtbl; designed for use by C and C+ programs and is put 'ROUTINE MessageBoxA' / the most direct way for software applications to ' MODULE=USER32 ' / interact with Windows systems. The SAS Batch ' MINARG=4 ' / application uses it to create a Message Box to ' MAXARG=4 ' / inform the user that a line of SAS program code ' STACKPOP=called ' / must not exceed 80 characters, a requirement of ' RETURNS=short ; ' / this Mainframe process. ' ARG 1 input num format=pib4. byvalue;' / ' ARG 2 input char format=$cstr200.; ' / ' ARG 3 input char format=$cstr200.; ' / ' ARG 4 input num format=pib4. byvalue;' ; run;

6 NESUG 2006 Applications

*------*; JOB CONTROL LANGUAGE * Set up Job Control Statement *; *------*; JCL is a used on the IBM filename BatchPgm temp; mainframe to instruct the Job Entry Subsystem (JES) how to run a batch program. data _null_;

*** Create Batch Program ***; The SAS Batch application will create the JCL file BatchPgm; needed to run the process. Each record of the SAS program is imported into a and its *** Import SAS program ***; length checked for the maximum, 80 characters. infile "&SasProg" truncover length=length; input SAS_Code $80.; During the processing of the first record (_N_=1)

*** Export program to Batch process ***; SAS will create the JOB CARD and JCL that JES call symput('ERROR','N'); will use to execute the SAS program. if length > 80 then do; text = 'The width the SAS program needs to be less than 80 characters!'; style = 4096+48+0; rc = MODULEN('*e','MessageBoxA',0,text,'ERROR!', style); call symput('ERROR','Y'); JOB CARD stop; end; This is the first statement JES will see else do; and is used to set up the batch session. if _N_=1 then do; *** Set up the Job Card ***; PUT "//*------* "/ The SAS Batch application assumes "//* JOB CARD FROM PC SAS * "/ the Windows and Mainframe user-ids "//*------* "/ are the same. It uses the SYSUSERID "//%upcase(&SYSUSERID)BTCH JOB ACNT123456, "/ macro variable to set up the JCL. "// SASBATCH,MSGLEVEL=(1,1),MSGCLASS=Q "/ "//STEP1 EXEC SAS "/ STEP1 of the JCL is to execute the "//SYSIN * "/ SAS System. The command in this "*------*;"/ example is SAS . The executable for "* PROGRAM FROM PC SAS *;"/ "*------*;"/ launching the system may be different SAS_Code; on other mainframes. end; else do; SYSIN is the command that tells JES the next line will put SAS_Code; start the program code for the SAS System. Hence the end; end; SAS_Code variable will then output the code into the run; temporary BatchPgm file.

ENDSUBMIT; RSUBMIT *------*; * Verify there are no ERRORs *; *------*; This command is part of the SAS/CONNECT software. It if symget('ERROR') = 'Y' then RETURN; tells the system the next line of code is to be executed on else SUBMIT CONTINUE; the remote machine. In this case the IBM Mainframe.

*------*; The process continues submitting SAS statements on * Submit Mainframe Batch Job *; the remote machine unti l it encounters the ENDRUBMIT *------*; command. RSUBMIT rmthost;

*** Upload program and submit via Internal Reader ***; filename IntReadr pgm=INTRDR sysout=A recfm=FB lrecl=80;

proc upload infile=BatchPgm INTERNAL READER

outfile=IntReadr status=no; The Internal Reader ( INTRDR ) is a program to execute SAS code. The run; FILENAME statement is used to point to this file and sets required options.

ENDRSUBMIT; The PROC UPLOAD is used to upload the SAS program located in the temporary BatchPgm and submit the code via the IntReadr File Reference. 7 NESUG 2006 Applications

*------*; * Send user a message that job is submitted *; MODULEN *------*; data _null_; This calls a routine external to the SAS System and text = 'Your Batch job has been submitted.'; returns a numeric value. T he SAS Batch application uses style = 4096+48+0; it to call the Message Box created earlier. In this instance rc = MODULEN('*e','MessageBoxA',0,text, it sends a message informing the user the batch job has 'SAS Batch Message', style); run; been submitted. This call was also used earlier in the program to inform the user a program is longer than 80 ENDSUBMIT; characters.

RETURN;

OVERVIEW

This simple SAS Batch application has a total of three Labeled sections, INIT, SELECT, and SUBMITPGM; two SUBMIT blocks; and one Remote Submit (RSUBMIT) block.

1 The INIT section is used to initialize the variables and set up the environment. * Initialize Variables 1 INIT: ...SCL... 2 The SELECT section is used to identify the SAS program RETURN; that will be executed on the mainframe. * Select PC File to Submit The SUBMITPGM section is used to read the program, 2 SELECT: ...SCL... 3 RETURN; create the Job Control Language (JCL), and logon to the IBM mainframe and submit the batch job. * Submit the Selected Program SUBMITPGM: if txt_SasProg.text = " " ... then This area of the SCL checks to make sure a valid 4 4 SAS program has been selected. If not, control will RETURN; RETURN to the Frame. else * Submit SAS Statements SUBMIT CONTINUE; If the name of the SAS program is valid the next * SIGNON to Mainframe step is to ensure it is not over 80 characters in * Set up Message Box via Windows API 5 width and create the JCL. This needs to be done * Set up Job Control Statement in a SAS DATA step, which requires the use of 6 5 * Import PC program the SUBMIT CONTINUE block. * Export Mainframe program if length > 80 then 'ERROR!' This is another Error Handling step that will else 6 * Set up the Job Card (JCL) RETURN control to the Frame in the event 3 ENDSUBMIT; an error has occurred. * Verify there are no ERROR's If no error is encountered a second SUBMIT if symget('ERROR') = 'Y' then 7 block is issued to CONTINUE executing. RETURN; else The final step will upload and submit the SUBMIT CONTINUE; 8 * Submit Mainframe Batch Job program to the mainframe and send a message RSUBMIT rmthost; 7 8 to the user that the job has been submitted. ENDRSUBMIT; * Send message that job submitted ENDSUBMIT;

RETURN;

8 NESUG 2006 Applications

SUMMARY

The ability to submit mainframe batch jobs only requires SAS/Connect. The use of SAS/AF allows the creation of a dynamic application, though is not mandatory. The code below is all that is truly requisite:

//A243BTCH JOB ABC123,A123 //STEP01 EXEC SAS8 //SYSIN DD *

data test; test_var = "Submit Batch Job."; run;

CONCLUSION

The SAS System is often viewed as software for producing only statistics. In fact, it is one of the premier applications for creating statistics in the world so no wonder it may only be recognized for its ability to create analytics. In actuality SAS has a multitude of products to interact with other operating systems and create user friendly front-end Graphical User Interfaces giving the power of SAS analytics to the masses.

REFERENCES

AndrewSoft 2006, “SAS® Batch Application for IBM® Mainframe”, http://geocities.com/andrews4art

SAS Institute Inc. 1999, SAS® OnlineDoc® Version Eight. “SAS Macro Language Reference.” http://v8doc.sas.com/sashtml/.

SAS Institute Inc. 2006, SAS® OnlineDoc® Version Eight. “Submitting a Batch Job on a Remote MVS Host from Your Local SAS Session” http://support.sas.com/documentation/periodicals/obs/obswww24/index.html

Wilson S. (2002), “Getting Started with SAS/AF® Software”, Proceedings of the Twenty-seventh Annual SAS Users Group International Conference, 27, 193-27.

ACKNOWLEDGMENTS

The author would like to thank the CMS SAS User Group and the Office of Research, Development, and Information.

CONTACT INFORMATION Your comments and questions are valued and encouraged.

Rick Andrews Centers for Medicare and Medicaid Services Office of Research, Development, and Information 7500 Security Boulevard Baltimore, MD 21244 Phone: (410) 786-4088 E-mail: [email protected]

SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.

9