Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

SYSTASK: The Spawn of SAS Programmers

Spawn: Produce or generate in large numbers. The Pocket Oxford English Dictionary, 8th Edition, Clarendon Press, Oxford, 1992.

Spawning SAS® sessions may not be a familiar phrase, unless you hold a role of Platform Administrator or perhaps have configured a SAS/CONNECT spawner. This is simply the process of creating a process from within another, such as launching a SAS session from an existing SAS session. There are various means of achieving this in Base SAS, SAS/CONNECT® and SAS Integration Technologies®; here we consider a global statement called SYSTASK found in Base SAS.

A basic example of the SYSTASK statement can be used to open the Calculator on Windows:

systask command "calc";

Amadeus regularly automates SAS the "old fashioned way" for customers without the Intelligence Platform by using command line scripts such as:

START "Batch" /wait /min 
	"C:\Program Files\SASHome\SASFoundation\9.3\SAS.EXE"
	-batch -nosplash -sysin "D:\Program1.sas" 
	-log "D:\Program1.log"

Now what if we had several SAS programs that we wanted to run either synchronously or asynchronously and what if that list of programs was to be determined within SAS logic itself? The above START command line can be generalised into a SYSTASK statement as follows:

systask command "START ""Batch"" /wait /min 
      ""%sysget(sasroot)\sas.exe"" -batch -nosplash 
        -sysin ""D:\Program1.sas"" 
        -log ""D:\Program1.log"" " wait;

Notice how we have used two pairs of double quotation marks to build up strings, allowing both the resolution of macro variables and spaces in paths. The %sysget(sasroot) macro function resolves the installation location of SAS on Windows operating systems.

The WAIT keyword tells SAS to suspend processing of further statements until the SYSTASK command is completed. Without this, SAS would process subsequent steps and statements in your program. However, the ability to run many jobs at once is useful when CPU resources are underutilised in long running processes. Such a scenario may resemble the following:

systask command "START ""Batch"" /wait /min 
    ""%sysget(sasroot)\sas.exe"" -batch -nosplash 
    -sysin ""D:\Program1.sas"" -log ""d:\Program1.log"""
    taskname=prepare_data wait;

systask command "START ""Batch"" /wait /min

    ""%sysget(sasroot)\sas.exe"" -batch -nosplash 
    -sysin ""D:\Program2.sas"" -log ""d:\Program2.log"""
    taskname=job1_for_data;

systask command "START ""Batch"" /wait /min

    ""%sysget(sasroot)\sas.exe"" -batch -nosplash
    -sysin ""D:\Program3.sas"" -log ""d:\Program3.log"""
    taskname=job2_for_data;

systask command "START ""Batch"" /wait /min

    ""%sysget(sasroot)\sas.exe"" -batch -nosplash
    -sysin ""D:\Program4.sas"" -log ""d:\Program4.log"""
    taskname=job3_for_data;

waitfor _all_ job1_for_data job2_for_data job3_for_data;

In the above example SAS suspends processing at the first SYSTASK statement where, for example, you may be preparing data for repeated use later on. The next three SYSTASK statements run asynchronously. The final WAITFOR statement prevents any further steps in the program from running until all of these jobs have completed.

Note: Those programming in Enterprise Guide and attempting to execute SYSTASK statements on their Workspace Servers will likely receive a message indicating unauthorised access. The following link discusses why and provides a resolution: http://support.sas.com/kb/41/058.html.

Finally, consider generalising these examples with the macro language to dynamically run varying jobs based on the rules you desire.