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.


X statement

From sasCommunity
(Redirected from X command)
Jump to: navigation, search
This is a work in progress. You can contribute to this article.

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.

Syntax

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.

Execution

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.

Return code

The X statement populates the automatic macro variable SYSRC with the ERRORLEVEL value returned by the operating system when the command is executed.

Usage

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.

See also

  • CALL SYSTEM routine
  • %SYSEXEC macro statement
  • SYSTASK statement
  • SYSRC automatic macro variable
  • XCMD system option
  • XSYNC system option
  • XWAIT system option

Further reading

sasCommunity articles

External links

SAS Documentation