Monday, November 26, 2012

Command line arguments in SAS / SAS System Options

Most often than not, we tend to run the SAS program in command lines. If the SAS is present in UNIX, we open a client terminal like PuTTY or SSH terminal and invoke the SAS program. If the SAS is present in Windows, then we can do the same by opening command mode.

The sytax for invoking the SAS Program is as follows:

sas <path and program-name>.sas

We need to make sure that the path of sas executable is present in the PATH enviroinment variable.

What is more interesting are the other command line arguments that we can pass while invoking a SAS program as mentioned above in the command line. Below, I've tried to illustrate each of them with the sytax and usage detail:

  • SYSPARM: This is the most useful option that I have come across. This lets us send parameters to the SAS programs through the command line prompt. The value of the SYSPARM is saved under the macro variable- SYSPARM, which can be accessed within the program. For Example, the below code - lets us send the age as a parameter while invoking the SAS Program.
     %put &sysparm;

     proc print data=sashelp.class noobs;
     where age=&sysparm.;

           We can invoke the SAS program in the command mode as follows:

           sas -sysparm "14"

    One can even send a list of key-value pair values through the program which will feed-in to a macro.
  • LOG: This option would redirect the log file to the specified location instead of the default location.
          Usage:     sas -log "~/temp.log"
  • WORK: This would help us specify the work directory location instead of the default work place.
I also found that SAS 9.3 has come up with new options to use Checkpoint Mode and Restart Mode for Labeled Code Sections if the program has terminated in the middle and if we need to restart it from a specific point onwards. More to come in this in the next post!

Let me know your thoughts!