As the first step in the decommissioning of 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 vs. CALL SYSTEM

From sasCommunity
Jump to: navigation, search

Both the X statement and the CALL SYSTEM routine allow you to execute external commands from within SAS. There are important differences, however.

SAS executes the X statement immediately when it encounters it. So, it's best used for something that you want to do between one SAS step (DATA step or PROC) and the next, or at the very beginning or end of your program. In general, the exact text for the command is known in advance when you are writing the program. Since it is a global statement, it returns a status code, which can be inspected to confirm that the function call worked as expected.

CALL SYSTEM is an executable DATA step function. It can only be used within a DATA step (duh), and is executed when the DATA step executes (rather than when it is compiled). It is generally used when you need to include values from the DATA step in the construction of the command, execute the command multiple times (perhaps for every observation in a data set), and/or execute the command conditionally (IF ... THEN CALL SYSTEM (...) ).

Other variants include SYSTASK in the DATA step and %SYSEXEC in the macro language.