Chapter Contents

Previous

Next
SAS Companion for the OS/2 Environment

Issuing OS/2 Commands from within SAS

You can execute OS/2 commands from your SAS session either asynchronously or synchronously. When you run a command as an asynchronous task, the command executes independently of all other tasks that are currently running. To run a command asynchronously, you must use the SYSTASK statement. For more information about running asynchronous commands using the SYSTASK statement, see SYSTASK.

When you execute one or more OS/2 commands synchronously, then you must wait for those commands to finish executing before you can continue working in your SAS session. You can use the CALL SYSTEM routine, X statement, and X command to execute OS/2 commands synchronously. The CALL SYSTEM routine can be executed with a DATA step and the X statement can be used outside DATA steps. You can enter the X command on any SAS command line.

You can submit the X statement to exit your SAS session temporarily and gain access to the OS/2 command processor. The X statement takes the form

X <'command'>;

The optional command argument is used either to issue an operating environment command or to invoke an OS/2 application such as the OS/2 System Editor. This discussion concentrates on using the X statement to issue operating environment commands; note, however, that the X statement can also be used to invoke OS/2 applications.

Note:   The X statement is similar to the X command. The major difference between the two is that the X statement is submitted like any SAS statement; however, the X command is issued as a windowing environment command. This section uses the X statement in examples, but the information applies to the X command as well.  [cautionend]

If you want to issue only one operating environment command, include the command as an argument in the X statement. When you submit the X statement, the command is issued, and you cannot issue any additional commands.

If you want to issue several operating environment commands, submit the X statement without an argument. A command prompt appears where you can enter an unlimited number of operating environment commands. Remember, however, that the commands that you issue from the command prompt do not affect the SAS process. For example, if you change from the SAS working folder to MYDATA at the command prompt, the SAS System still uses the SAS folder as its working folder. Also, any environment variables that you define are not available to the SAS System. If you submit an X statement or command without a command argument, type EXIT to return to your SAS session.

Other methods of temporarily exiting your SAS session include


Executing Operating Environment Commands Conditionally

If you want to issue operating environment commands conditionally, use the CALL SYSTEM routine, as in the following example:

options noxwait;
data _null_;
   input flag $ name $8.;
   if upcase(flag)='Y' then
      do;
         command='md c:\'||name;
         call system(command);
      end;
   cards;
Y mydir
Y junk2
N mydir2
Y xyz
;

This example uses the value of the variable FLAG to conditionally create folders. After the DATA step runs, three folders have been created: C:\MYDIR, C:\JUNK2, and C:\XYZ. The folder C:\MYDIR2 is not created because the value of FLAG for that observation is not Y.

The X command is a global SAS statement; therefore, it is important to realize that you cannot conditionally issue the X command. For example, if you submit the following code, the X statement is issued:

data _null_;
   answer='n';
   if upcase(answer)='y' then
      do;
         x 'md c:\extra';
      end;
run;

In this case, the folder C:\EXTRA is created regardless of whether the value of ANSWER is equal to n or y.

For more information about the CALL SYSTEM routine, see CALL SYSTEM and the section on functions and CALL routines in SAS Language Reference: Dictionary.


XWAIT System Option

The XWAIT system option controls whether you have to type EXIT to return to your SAS session after an X statement or command has finished executing a DOS command. (The XWAIT system option is not used if an X statement is issued without a command argument or if the X statement invokes an OS/2 application such as the EPM editor.) This option and its negative form operate in the following ways:
XWAIT specifies that you must type EXIT to return to your SAS session. This is the default behavior.
NOXWAIT specifies that the command processor automatically return to the SAS session after the specified command is issued; you do not have to type EXIT.
If you issue an X statement or command without a command argument, you must type EXIT to return to your SAS session, even if NOXWAIT is in effect.

When a window that was created by an X statement is active, reactivating the SAS System without exiting from the command processor causes the SAS System to issue the following message:

   The X command is active. Enter EXIT at 
   the prompt in the X command window to 
   reactivate this SAS session.

If you receive this message, type the EXIT command from the command prompt to close the window and return to your SAS session.


XSYNC System Option

The XSYNC option specifies whether the operating environment command that you submit runs synchronously or asynchronously with your SAS session. This option and its negative form operate in the following ways:
XSYNC causes the operating environment command to run synchronously with your SAS session. That is, control is not returned to the SAS System until the command has completed. You cannot return to your SAS session until the command prompt session that was spawned by the X command or statement is closed. This is the default behavior.
NOXSYNC indicates that the operating environment command should run asynchronously with your SAS session. That is, control is returned immediately to the SAS System, and the command continues executing without interfering with your SAS session. With NOXSYNC in effect, you can invoke an X command or statement and return to your SAS session without closing the window that was spawned by the X command or statement.

Specifying NOXSYNC can be useful if you are starting applications such as the EPM editor from your SAS session. For example, suppose you submit the following X statement:

x epm;

If XSYNC is in effect, you cannot return to your SAS session until you close EPM. But if NOXSYNC is in effect, you can switch back and forth between your SAS session and the NOTEPAD. The NOXSYNC option breaks any ties between your SAS session and the other application. You can even end your SAS session. The other application stays open until you close it.


Comparison of the XWAIT and XSYNC Options

The XWAIT and XSYNC options have very different effects. An easy way to remember the differences is the following:
XWAIT means the command prompt session waits for you to type EXIT before you can return to your SAS session.
XSYNC means the SAS System waits for you to finish with the other application before you can return to your SAS session.

The various option combinations are summarized in Combining the XWAIT and XSYNC System Options.

Combining the XWAIT and XSYNC System Options
Options in Effect Result
XWAIT

XSYNC

The command prompt window waits for you to type EXIT before closing, and the SAS System waits for the application to finish.
XWAIT

NOXSYNC

The command prompt window waits for you to type EXIT before closing, and the SAS System does not wait for the application to finish.
NOXWAIT

XSYNC

The command prompt window closes automatically when the application finishes, and the SAS System waits for the application to finish.
NOXWAIT

NOXSYNC

The command prompt window closes automatically when the application finishes, and the SAS System does not wait for the application to finish.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.