Writing Simple SAS/CONNECT Scripts for Signing On and Signing Off

Writing Simple SAS/CONNECT Scripts: Overview

When you write or modify existing SAS/CONNECT scripts, use the WAITFOR and TYPE statements to specify the sequence of prompts and responses for the server.
The simplest method for determining the sequence is to manually reproduce on the server the process that you want to capture in the WAITFOR and TYPE statements. For each display on the server, choose a word from that display for the WAITFOR statement. Whatever information you type to respond to a display should be specified in a TYPE statement. Be sure to note all carriage returns or other special keys.
If the server runs under z/OS and you need to use a TYPE statement that has more than 80 characters in a sign-on script, divide the TYPE statement into two or more TYPE statements. To divide the TYPE statement, insert a hyphen (-) at the division point. The z/OS server interprets the hyphen as the continuation of the TYPE statement from the previous line. For example, here is how to divide the following TYPE statement:
type 
"sas options ('dmr comamid=tcp')" 
enter;
change it to:
type "sas options ('dmr comamid=-" enter;
type "tcp')" enter;
Note: Do not insert spaces before or after the hyphen.

Example SAS/CONNECT Script for a TCP/IP Connection to UNIX

/* trace on; */
/* echo  on; */
   /*******************************************/
   /* Copyright (C) 1990                      */
   /* by SAS Institute Inc., Cary NC          */
   /*                                         */
   /* name:    tcpunix.scr                    */
   /*                                         */
   /* purpose: SAS/CONNECT SIGNON/SIGNOFF     */
   /*          script for connecting to any   */
   /*          UNIX operating environment     */
   /*          via the TCP/IP access method   */
   /*                                         */
   /* notes:   1. This script might need      */
   /*             modifications that account  */
   /*             for the local flavor of     */
   /*             your UNIX environment. The  */
   /*             logon procedure should      */
   /*             mimic the tasks that you    */
   /*             execute when                */
   /*             connecting to the same      */
   /*             UNIX operating environment. */
   /*                                         */
   /*          2. You must have specified     */
   /*             OPTIONS COMAMID=TCP in the  */
   /*             client session before       */
   /*             using the SIGNON command.   */
   /*                                         */
   /* assumes: 1. The command to execute SAS  */
   /*             in your remote (UNIX)       */
   /*             environment is "sas". If    */
   /*             this is incorrect for your  */
   /*             site, change the contents   */
   /*             of the line that contains   */
   /*             type 'sas ...               */
   /*                                         */
   /* support: SAS Institute staff            */
   /*******************************************/

 1log "NOTE: Script file 
                'tcpunix.scr' entered.";

   if not tcp then goto notcp;
 2if signoff then goto signoff;

   /*******************************************/
   /*  TCP/IP SIGNON                          */
   /*******************************************/

 3waitfor 'login:', 120 seconds: noinit;

   /*******************************************/
   /*  UNIX LOGON                             */
   /* LF is required to turn the line         */
   /* around after the login name has         */
   /* been typed. (CR will not do)            */
   /*******************************************/
 4input 'Userid?';
   type LF;
 5waitfor 'Password', 30 seconds : nolog;
   input nodisplay 'Password?';
   type LF;

unx_log:
   /*******************************************/
   /* Common prompt characters are $,>,%,}    */
   /*******************************************/
 6waitfor '$', '>', '%', '}',
      'Login incorrect'      : nouser,
      'Enter terminal type'  : unx_term,
      30 seconds             : timeout;


   log 'NOTE: Logged onto UNIX... 
              Starting remote SAS now.';

      /****************************************/
      /* Invoke SAS on the server.       */
      /****************************************/
 type 'sas -dmr -comamid tcp -device 
       -noterminal -nosyntaxcheck' LF;
 waitfor 'SESSION ESTABLISHED', 
      90 seconds : nosas;

 log 'NOTE: SAS/CONNECT 
      conversation established.';
   stop;

   /*******************************************/
   /*  TCP/IP SIGNOFF                         */
   /*******************************************/
10 signoff:
waitfor '$', '>', '%', '}',
      30 seconds;

   type    'logout' LF;
   log 'NOTE: SAS/CONNECT conversation 
        terminated.';
   stop;

   /*******************************************/
   /*  SUBROUTINES                            */
   /*******************************************/
unx_term:

      /****************************************/
      /* Some UNIX systems want the           */
      /* terminal-type. Indicate a basic      */
      /* tele-type.                           */
      /****************************************/
   type 'tty' LF;
   goto unx_log;

   /*******************************************/
   /*  ERROR ROUTINES                         */
   /*******************************************/
 11timeout:
   log 'ERROR: Timeout waiting for remote 
      session response.';
   abort;

nouser:
   log 'ERROR: Unrecognized userid or 
               password.';
   abort;

notcp:
   log 'ERROR: Incorrect communications 
               access method.';
   log 'NOTE: You must set "OPTIONS 
              COMAMID=TCP;" before using 
              this script file.';
   abort;

noinit:
   log 'ERROR: Did not understand remote 
               session banner.';

nolog:
   log 'ERROR: Did not receive userid or 
               password prompt.';
   abort;

nosas:
   log 'ERROR: Did not get SAS software 
               startup messages.';
   abort;
1 The LOG statement sends the message that is enclosed in quotation marks to the log file or the log window of the client session. Although it is not necessary to include LOG statements in your script file, the LOG statements keep the user informed about the progress of the connection.
2The IF/THEN statement detects whether the script was called by the SIGNON command or statement or the SIGNOFF command or statement. When you are signing off, the IF/THEN statement directs script processing to the statement labeled SIGNOFF. See step 10.
3The WAITFOR statement waits for the server's logon prompt and specifies that if that prompt is not received within 120 seconds, the script processing should branch to the statement labeled NOINIT.
4 The INPUT statement displays a window with the text Userid? to allow the user to enter a server log-on user ID. The TYPE statement sends a line feed to the server to enter the user ID to the server.
5The WAITFOR statement waits for the server's password prompt and branches to the NOLOG label if it is not received within 30 seconds. The INPUT statement that follows the WAITFOR statement displays a window for the user to enter a password. The NODISPLAY option is used so the password is not displayed on the screen as it is entered.
6The WAITFOR statement waits for one of several common UNIX prompts and branches to various error handles if a prompt is not seen. Verify that the WAITFOR statement in the script looks for the correct prompt for your site.
7This TYPE statement invokes SAS on the server. The -DMR option is necessary to invoke a special processing mode for SAS/CONNECT. The -COMAMID option specifies the access method that is used to make the connection. The -NOTERMINAL system option suppresses prompts from the server session. The -NOSYNTAXCHECK option prevents the remote session from going into syntax checking mode when a syntax error is encountered.
8The phrase SESSION ESTABLISHED is displayed when a SAS session is started on the server by using the options -DMR and -COMAMID TCP. The WAITFOR statement looks for the words SESSION ESTABLISHED to be issued by the server session to know that the connection has been established. If the SESSION ESTABLISHED response is received within 90 seconds, processing continues with the next LOG statement. If the SESSION ESTABLISHED response does not occur within 90 seconds, the script assumes that the server session has not started and processing branches to the statement labeled NOSAS.
9 When the connection has been successfully established, you must stop the rest of the script from processing. Without this STOP statement, processing of the remaining statements in the script continues.
10This section of code is executed when the script is invoked to end the connection. The second IF statement (see step 2) sends processing to this section of the script when the script is invoked by a SIGNOFF command or statement. Note that this section waits for a server prompt before typing LOGOUT in order to log off the server. The script then issues a LOG statement to notify the user that the connection is terminated and stops script processing.
11These statements are processed only if the prompts expected in the previous steps are not received. This section of the script issues messages to the local SAS log and abnormally ends (from the ABORT statement) the processing of the script as well as the signon.