"Batch" Submission


SAS 6.12 Update

As far as I know, everything in this document should still be accurate under version 6.12. The "Customize Drop Actions" menu has been renamed to "Customize File Types" and the dialog has been redesigned, but it still works the same way.

The Problem

In interactive mode, using SAS for the Mac is pretty straightforward. Put your program in the program editor, submit it, and you get the log in the log window and the output in the output window.

What I wanted to do was figure out a way to run in "batch mode"--that is, I wanted to be able to tell SAS to take a text file containing a SAS program, run the program, and save .log and .lst files in the same directory, without having to manually tell SAS to save the log and output after the job was running. Ideally, I wanted a drag-and-drop solution--write the program in an editor, drop the program's icon onto SAS, and have the .log and .lst files show up in the right place with no further activity.

(Note the difference between "batch" and "background" on the Mac--while I found a way to run a SAS job in "batch mode", it's still a foreground process and you can't use the Mac for other tasks while it's running.)

Thanks are due to the folks at SAS tech support for getting me on the right track to figure this out...


The (New) Solution

Look around for the "Invoke SAS" scripting extension, which is provided on the SAS System CD starting with the February 1996 Usage Notes release. This file is inside the "SAS Extras" folder, which is inside the "updates" folder (or you could just use Find File, of course). To install the extension, put a copy of it into the Scripting Extensions folder, which is inside the Extensions folder in your system folder. You may need to restart your machine to have access to the extension.

This extension, which has a documentation file in the same folder on the CD-ROM, adds the "Invoke SAS" and "Locate SAS" commands to AppleScript's vocabulary. These commands let you use the versatility of AppleScript to SAS.

For a quick and easy start, you want to download the Drop SAS script (49K) from this site. Decode and expand it (it's a binhexed self-expanding Stuffit archive).

In order to run your SAS program in batch mode, all you have to do is drag the program's icon onto the Drop SAS application. That's it. SAS will start, execute your program, and finish, leaving .log and .lst files in the same folder as your program.

If you're familiar with AppleScript and want to work with the Invoke SAS command on your own, feel free to use the Drop SAS application as a starting point. Also check out the BBEdit SAS Script Package (74K) for some more examples of using AppleScript to make it easier to work with SAS.


The (Old) Solution

Before I developed the Drop SAS script application, I developed a way to use SAS's customizable drop actions to make SAS run in "batch mode". Here's how to set it up....

  1. From the "File" menu, go to the "Preferences" submenu and select "Customize Drop Actions...". This will bring up a window which lets you tell SAS what to do when you drop a file onto it.

  2. SAS programs are text files--the file type code is TEXT--so you want to make sure "TEXT - Textfile" is selected from the "File Descriptor" pop-up menu.

  3. Now, you need to tell SAS what to do when you drop a TEXT file on it; the default specification is

    include '^1';

    which simply loads the file into the program editor. The "^1" refers to the full path and name of the file dropped; the window shows other codes you can use to refer to just the path, just the filename, and so on.

    What we want SAS to do is read the program, run it, save the .log and .lst files, and quit. To do this, enter the following code in the "Default Action:" box:

    include '^1'; submit; log; file '^2^4.log'; listing; file '^2^4.lst'; endsas;

    Note that the caret (^) is just a shift-6, not a control character. Also, SAS will not permit you to paste into the "Default Action:" box--you will have to type the code directly.

    This tells SAS to:

    1. Load the file you've just dragged onto it, in the program editor window.
    2. Run the SAS program.
    3. Go to the log window, and save the contents in a .log file in the same folder as the program.
    4. Go to the output window, and save the contents in a .lst file in the same folder as the program.
    5. Quit SAS and return to the Finder.

  4. Now, you can use any text editor to write your program. If you then go to the Finder, take the icon for your SAS program, and drop it onto the SAS application icon, it will run and generate the .log and .lst files. You can then view and/or print the output in SAS or in any text editor you choose.

    One caveat: the drop action customization in SAS 6.10 for the Mac applies only to files dropped onto the SAS application's icon. In working with an experimental copy of SAS 6.12, I note that the customization now applies to files opened with SAS by any means, including through the standard Open dialog. This means that if you set things so programs run automatically when dropped on SAS, you will be unable to load a program into the program editor without running it. The "Invoke SAS" AppleScript extension (see above) is definitely the most flexible way to run batch SAS on the Macintosh.


Some Notes

Although the .log and .lst files are standard TEXT files, note that SAS does not stamp them with a creator code to indicate what program they belong to. Thus, they will have generic icons and must be opened from within a program rather than from the Finder.

If by some means (Drop*Attribute, ResEdit, Snitch, etc.) you attach the "SaS6" creator code to a text file (telling the Finder that SAS created the file), then double-clicking on that text file will cause SAS to do the same thing as dragging and dropping--in this case, run the job and create the .log and .lst files. Doing this to .log or .lst files would probably be a bad idea.

There are some other ways to invoke SAS in "batch" mode; most notably, an extension (called "Invoke SAS") allows SAS to be invoked via AppleScript. This lets you write an AppleScript command to invoke SAS with options (and to create the .log and .lst files) in a manner similar to the Unix command line method. There's also an application called "SAS Command" which, in effect, does the same thing. Once I have time to test these a bit, I'll post a report.


Return to SAS for the Macintosh.