Search notes:

SAS statements: x

x executes an operating system command. It requires the option xcmd to be set.

&sysrc

Executing a command sets the automatic variable &sysrc to the command's ERRORLEVEL.
%let cmd=ls /tmp;
x &cmd;
%put &cmd returned &sysrc;
/* ls /tmp returned 0 */

%let cmd=ls /non/existing/directory;
x &cmd;
%put &cmd returned &sysrc;
/* ls /non/existing/directory returned 2 */
Github repository about-SAS, path: /programming/statements/x/sysrc.sas

Capturing output

Unfortunately, the output of the x statement cannot (easily) be captured and is not written to the log file.
So, in order to capture the output of an operating command, filename pipe could be used.
Or the systask statement, which writes the executed command's output to the log file.

See also

Interaction with the OS
SAS statements

Index