0% found this document useful (0 votes)
34 views2 pages

Use of Autoexec - Sas

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

USING AUTOEXEC.

SAS TO CUSTOMIZE SAS SESSIONS


Jennifer Price - Independent Consultant
INTRODUCTION:
There are several features in SAS that can be used to
organize your SAS session before it begins. This paper
will examine how this can be done using
AUTOEXEC.SAS. One of the features of
AUTOEXEC.SAS is that it can be customized for
different projects. For example, most projects have a
unique libname, format library and macro library. You
may have standard libnames, formats and macro libraries
as well. These can all be set up using AUTOEXEC.SAS.
The SAS AUTOEXEC.SAS is an external file located
in the same physical location as SAS.EXE. It is run
when SAS is executed.
The solution I found to organize my sessions by project is
the following:
Each project has a libname that is unique to that
project. This libname is used by all programmers
and in all programs related to that project.
Each project has a format library. Each programmer
adds the formats they need to a single library that is
then accessed by all programmers on the project.
Each project has a macro library in addition to the
standard macro library used in all projects
My AUTOEXEC.SAS lists all the libnames for the
different projects, and defines the format library and the
macro library for the project that I am currently working
on. There is a solution for working on multiple projects
that is noted late in the paper.

libname project1 c:\project1\sasdata;


libname project2 c:\project2\sasdata;
By putting the LIBNAME statement in the
AUTOEXEC.SAS, we dont need to have a libname
statement in each program. This is especially helpful
when working at multiple locations where the path
names are different. In one location I may define the
libname project1 as:
c:\my_documents\work\project1\sasdata; and at another
it might be defined as t:\project1\sasdata;.
By defining all of the libnames in the AUTOEXEC.SAS
instead of individual programs, you can run programs
from different locations (i.e. home or work). Since all
programs refer to the datasets as
PROJECT1.DSETNAME, they all find the data they
need without modifying the program.
options macautosource sasautos =
(c:\project1\sasmacro c:\library\macros);
The MAUTOSOURCE option causes the macro
processor to search the autocall libraries for a member
with the requested name when a macro name is not found
in the work library.
The SASAUTOS= option tells SAS where to search for
autocall macro libraries. When two or more autocall
macro libraries are specified, SAS searches each
location in the same order that is specified in the
SASAUTOS option. If there are two or more locations
that contain macro libraries, they are enclosed in
parenthesis, and separated by either a comma or blank
space.

Example of a simple AUTOEXEC.SAS:


libname project1 c:\project1\sasdata;
libname project2 c:\project2\sasdata;
options macautosource sasautos =
(c:\project1\sasmacro c:\library\macros);
libname library c:\project1\sasdata;
proc format library=library;
run;

libname library c:\project1\sasdata;


proc format library=library;
This LIBRARY libname is a reserved SAS libname
that tells programs where the FORMAT library is
located. This is helpful when using projects that have
different formats associated with them. By using this
statement, I dont have to run the program that creates
the formats prior to running the program that uses the
formats. For each project I have a program that I call
FORMAT.SAS that has all of the formats for that
project. I need to run this once to create the
FORMAT.SC2 catalog in the data library. The PROC
FORMAT option must have the following syntax: PROC
FORMAT LIBRARY=LIBRARY;

Example of a PROC FORMAT using the LIBRARY


option:
The LIBRARY=LIBRARY option tells SAS to save the
output as a permanent SAS catalog. By using this
method, the PROC FORMAT only needs to be run once,
then the library will be available to all SAS sessions
using the PROC FORMAT LIBRARY=LIBRARY
statement (above). The PAGE option prints the output of
the format.
PROC FORMAT LIBRARY=LIBRARY PAGE;
value yesno
1=Yes
2=No
3=Unknown
4=N/A
.=-;
value $sex

M=Male
F=Female;

value $race

C=Caucasian
B=Black
H=Hispanic
other=Other;

SOLUTION FOR MULTIPLE PROJECTS:


For multiple projects, set up your AUTOEXEC.SAS with all
of your libnames, then put the remaining definitions for
the particular project that you are working on in a
different file (AUTOPJ2.SAS in this example). Use the
AUTOEXEC= option to specify the location of the
project specific file. If you are working on PROJECT2,
the last line in your AUTOEXEC.SAS would appear as
follows: AUTOEXEC=C:\PROJECT2\AUTOPJ2.SAS.
OPTIONS:
The following are some additional helpful options that
can be used in the OPTIONS statement:
MPRINT specifies whether SAS statements generated
by macro execution are displayed
SYMBOLGEN specifies whether the macro processor
displays the result of resolving macro variable references.
Example:
OPTIONS
AUTOEXEC=c:\project1\sasprog\proj1aut.sas
MPRINT SYMBOLGEN;
CONCLUSION:
AUTOEXEC.SAS can be used to organize libname
statements and format libraries, so that all programs
using the same libnames can have data residing in
different places, without recoding parts of the program.

References:
SAS Language Reference, Version 6, 1ed 1990, SAS
Institute, Inc., Cary, NC.
SAS Macro Language: Reference, 1ed 1997, SAS
Institute, Inc., Cary, NC.

TO CONTACT THE AUTHOR:


Jennifer Price
Independent Consultant
13 Fairfield Drive
Newark, DE 19711
Phone: 302.894.0577
email: [email protected]

You might also like