CALL SYSTEM Routine: Windows

Submits an operating system command or a Windows application for execution.

Category: Special
Windows specifics: command must be a valid Windows command
See: CALL SYSTEM Routine in SAS Functions and CALL Routines: Reference

Syntax

CALL SYSTEM(command);

Required Argument

command

can be any of the following:

  • an operating system command enclosed in quotation marks or the name of a Windows application that is enclosed in quotation marks.
  • an expression whose value is an operating system command or the name of a Windows application.
  • the name of a character variable whose value is an operating system command or the name of a Windows application.

Details

If you are running SAS interactively, the command executes in a command prompt window. By default, you must enter exit to return to your SAS session.
Note: The CALL SYSTEM function is not available if SAS is started with NOXCMD.

Comparisons

The CALL SYSTEM routine is similar to the X command. However, the CALL SYSTEM routine is callable and can therefore be executed conditionally.
The values of the XSYNC and XWAIT system options affect how the CALL SYSTEM routine works.

Examples

Example 1: Executing Operating System Commands Conditionally

If you want to execute operating system commands conditionally, use the CALL SYSTEM routine:
options noxwait;
data _null_;
   input flag $ name $8.;
   if upcase(flag)='Y' then
      do;
         command='md c:\'||name;
         call system(command);
      end;
   datalines;
Y mydir
Y junk2
N mydir2
Y xyz
;
This example uses the value of the variable FLAG to conditionally create directories. After the DATA step executes, three directories have been created: C:\MYDIR, C:\JUNK2, and C:\XYZ. The directory C:\MYDIR2 is not created because the value of FLAG for that observation is not Y.
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 directory C:\EXTRA is created regardless of whether the value of ANSWER is equal to 'n' or 'y'.

Example 2: Obtaining a Directory Listing

You can use the CALL SYSTEM routine to obtain a directory listing:
data _null_;
   call system('dir /w');
run;
In this example, the /W option for the DIR command instructs Windows to print the directory in the wide format instead of a vertical list format.