You can use the X statement
or the X command to run Windows commands. The X statement can be run
outside of a DATA step. You can enter the X command in the command
bar or any SAS command line.
The X statement is similar
to the X command in the SAS windowing environment. 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 its examples, but the
information applies to the X command as well.
When you submit the
X statement that you exit your SAS session temporarily and gain access
to the Windows command processor. The X statement has the following
syntax:
The optional
command argument
is used either to issue an operating system command or to invoke a
Windows application such as Notepad. This discussion concentrates
on using the X statement to issue operating system commands. However,
you should be aware that the X statement can also be used to invoke
Windows applications.
If you want to run only
one operating system command, include the command as an argument to
the X statement. When you submit the X statement, the command is executed,
and you cannot issue any additional commands.
If you want to run several
operating system commands, submit the X statement without an argument.
A command prompt appears where you can issue an unlimited number of
operating system commands. Remember, any environment variables that
you define are not available to SAS. If you submit an X statement
or command without an argument
command,
type EXIT to return to your SAS session.
The X command is a global
SAS statement. Therefore, it is important to realize that you cannot
conditionally execute the X command. For example, if you submit the
following code, the X statement is executed:
data _null_;
answer='n';
if upcase(answer)='y' then
do;
x 'md c:\extra';
end;
run;
In this case, the
C:\EXTRA
folder
is created regardless of whether the value of ANSWER is equal to
'n'
or
'y'
.