As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.
Here are some tips for How to share your SAS knowledge with your professional network.
The X statement is a global statement that can be used to run an operating system command from within a SAS program. The statement is executed immediately.
- X < ' command ' > ;
- command is the text sring for the operating system command as it would be entered at the command prompt of the operating system that the SAS application is running on.
- Because the command is a text string that is passed to the operating system it needs to be enclosed in quotes.
- If the X statement is executed without a command then the operation system command interpreter shell is started. In an interactive windowing environment this can cause a command line window to open, depending on various option settings.
The X statement is a global statement and can appear anywhere in SAS code, including macro code. It is executed as soon as it is encountered by SAS in open code. If the X statement appears within a DATA Step or PROC Step it will be executed before the DATA Step or PROC Step runs. This means an X statement cannot be conditionally or iteratively executed in a DATA Step.
If the X statement appears in macro code it will only be executed when the macro code is interpreted and resolved into SAS code. This means it is possible to execute the X statement conditionally or iteratively in a macro only by using iterative or conditional macro statements.
Because the X statement can run system-level commands on a SAS server it is a restricted statement and is usually disabled, for security reasons, when SAS is installed on a server.
If you encounter any of the following error messages in a SAS log then these indicate the X statement and other statements that access the operating system shell have been disabled.
ERROR: Shell escape is not valid in this SAS session.
WARNING: Shell escape is not valid in this SAS session.
ERROR: Insufficient authorization to access PIPE.
Enabling Operating System Shell Access
The -XCMD command line option enables Operating System Shell Access while the -NOXCMD command line option or disables access. These settings need to be changed by the SAS System Administrator.
To enable or disable Operating System Shell Access, changes need to be made by the SAS System Administrator for the SAS system in question. The exact changes that are needed vary depending on how SAS runs and what operating system SAS runs under. In general the SAS System Administrator will need to edit server metadata, stop and start system services and change various configuration files that are used to start SAS. These changed need to be made with care as an incorrect setting can cause SAS to stop operating.
- CALL SYSTEM routine
- %SYSEXEC macro statement
- SYSTASK statement
- SYSRC automatic macro variable
- XCMD system option
- XSYNC system option
- XWAIT system option
- X statement vs. CALL SYSTEM (← links)
- Tips:Use X Commands within a SAS Program to Issue Commands to Windows or MS-DOS
- SAS Filesystem Toolbox
- Paper PO13 Applications for Running DOS Commands within SAS Na Li, Pharmacyclics, Sunnyvale, CA (2005)
- Running Windows or MS-DOS Commands from within SAS - SAS(R) 9.2 Companion for Windows, Second Edition
- Problem Note 41058: Unable to submit X commands from SAS® Enterprise Guide® connecting to a SAS® Metadata Server when running SAS® 9.2 or later
- Usage Note 15179: Executing the SYSTEM function and X Command via the SAS® Stored Process Server