Autoexecs—the SAS Enterprise Guide advantage

As I was preparing for a customer introduction to using SAS Enterprise Guide, I asked them to send me all the questions they had regarding the Enterprise Guide usage. It turned out that many of their questions can be answered with a single feature called an autoexec, or automatically executable file.
Handpicked Related Content: Creating reports in style with SAS Enterprise Guide
An autoexec file generally contains a mini SAS program that is run when the SAS System starts up. Autoexec files can help SAS developers eliminate many routine actions and repetitive tasks such as assigning libraries and SAS options, particularly when these routine actions set up an environment that is used from project to project and from program to program. They prove to be very handy whether you’re using SAS in either an interactive mode or in a batch mode.

Compared to the classical SAS programming, where the autoexec file executes on a startup of a SAS session, SAS Enterprise Guide provides more flexibility in determining when the code is run. You can customize the autoexec start-up sequence in SAS Enterprise Guide by using either user-specific autoexec or project-specific autoexec, or both.

If you are a SAS developer working solo on a proof of concept, you would definitely want a user-specific autoexec. However, if you work on a larger project as a team member and want to set up a common environment across the project then project-specific autoexec is the way to go. You can even combine both autoexecs, user-specific and project-specific, to get the best of each – access to the common project resources and yet have some convenience of your own personal environment, for concept testing, for example. Just don’t forget to remove your user-specific autoexec when you release your project back to the team.

Preparing the autoexec file

The first step is to prepare the code for your autoexec file. Autoexec files are routinely used to set up SAS data and format libraries, macro variables, SAS system options, etc. Here is a typical autoexec file:

%let saspath = D:\SAS\Lev1\SASApp\SASEnvironment;
%let projpath = D:\Projects\proj1;

/* SAS Format library */
libname fmtlib "&saspath\SASFormats";

option
fmtsearch=(fmtlib)
nodate
mautosource sasautos=('!SASROOT\sasautos', "&saspath\SASMacro", "&projpath\code")
;

/* Input data library */
libname dwlib ODBC datasrc=PROD_DTA schema=DBO user=Sasread PASSWORD="{sas001}T8teQzIkMq==" access=readonly;

/* Output data library */
libname rptlib BASE "&projpath\outdata";

/* Report folder */
filename htmlout "&projpath\reports";

For more information about how to create and use autoexec files, see the SAS® 9.4 Companion for Windows or SAS® 9.4 Companion for UNIX Environments.

Setting up a user-specific autoexec

In SAS Enterprise Guide, autoexec code can be set up to execute every time a connection to a workspace server is made:

From the top Menu bar: Tools -> Options ->SAS Programs

In the Additional SAS code section, select the checkbox for Submit SAS code when server is connected

To the right of this checkbox, click the Edit button and enter the code to be run whenever you connect to a workspace server. You can also reference an external SAS autoexec file, such as %include ‘/path/autoexec.sas’

Click the Save button to close the Edit window

Click the OK button to save and close the Options window

As you can see, there are two other options available to execute Additional SAS Code:

Insert custom SAS code before submitted code

Insert custom SAS code after submitted code

This additional SAS code is stored as a customization option in your instance of SAS Enterprise Guide, making them user-specific.

Setting up a project-specific autoexec

You can apply an additional “layer” of customization by creating a process flow named “Autoexec” in a Project Tree. That process flow can be set up to run automatically whenever your or a member of your project team opens the project.

You can put anything you want in this process flow: a program with library assignments or macro definitions, one or more "Assign Library" tasks, Upload or Download data set tasks, even custom tasks. Note that a project can contain only one process flow named “Autoexec”.

By default, when you open a project that has an Autoexec flow you are prompted to run the Autoexec process flow. You will see the following prompt asking if that's what you want to do:

However, if you prefer not to have this prompt pop up every time you open the project, you can change that behavior by setting an option on the top menu bar.

From the top Menu bar: Tools -> Options ->General

Select the checkbox for Automatically run “Autoexec” process flow when project opens

Click OK button to save and close the Options window.

Autoexec is a very convenient and powerful productivity feature of SAS Enterprise Guide. Use it to your advantage.

Additional resources

You asked for it: the Autoexec process flow shares a little more insight on advantages of autoexecs in SAS Enterprise Guide.

Check this paper for more tips on Writing Code in SAS® Enterprise Guide.

Handpicked Related Content: Creating reports in style with SAS Enterprise Guide
Autoexecs—the SAS Enterprise Guide advantage was published on SAS Users.