X Statement: Windows

Runs an operating system command or a Windows application from within a SAS session.

Valid in: anywhere in a SAS program
Windows specifics: Valid values for command
See: X Statement in SAS Statements: Reference

Syntax

X <'command'> ;

Without Arguments

places you in a Command prompt session, with an operating system prompt. Here you can execute Windows commands in the context of SAS working directory. There are some things that you cannot do from the Command prompt in this situation, such as define environment variables for use by your SAS session. (Environment variables must be defined before you invoke SAS). Type EXIT at the Command prompt and press Enter to return to your SAS session.

Optional Argument

command

specifies a Windows command or a Windows application. This argument can be anything that you can specify at a DOS prompt (including the SAS command). Therefore, you can use the X statement to execute Windows applications. The command can be enclosed in quotation marks, but this syntax is not required.

The command is passed to Windows and executed in the context of the working directory. If errors occur, the appropriate error messages are displayed.
By default, you must type EXIT to return to your SAS session after the command has completed execution. Also, by default, if you execute a Windows application such as Notepad, you must close the application before you can return to your SAS session. Specify NOXWAIT in an OPTIONS statement if you do not want to have to type EXIT. With NOXWAIT in effect, as soon as the command finishes execution, control is returned to your SAS session. Note, however, that if you execute a Windows application with the X statement, specifying NOXWAIT does not let you return to your SAS session until you close the application.
Another system option, XSYNC, controls whether you have to wait for the command to finish executing before you can return to your SAS session. If you specify NOXSYNC, you can start a Windows application with the X statement and return to your SAS session without closing the application. For additional details about these two system options, see XWAIT System Option: Windows and XSYNC System Option: Windows.

Details

The X statement issues a host command from within a SAS session when you run SAS in windowing mode. SAS executes the X statement immediately.
Under Windows, you can issue the X statement without the command argument.
There are other ways of running operating environment commands besides the X statement (and the X command) under Windows.
Note: If you are using Microsoft Windows XP or later, the maximum length of the string that you can use at the command prompt is 8191 characters. For more information, see the article about restrictions on string length in command lines available at OS Limitation Workaround.