I had a few questions about autoexec.sas. The all revolve around the issue of getting autoexec.sas to execute when launching the SAS IDE from a file. Having autoexec.sas placed in the same directory works great when running in batch, but doesn't when I launch the SAS IDE from the file. From what I've gathered, it has something to do with the way SAS assigns the working directory when launching (I guess it is assigned after autoexec would be searched for/executed? Definitely correct me if I'm wrong).
1) The biggest question: Is there a work around for this? Ideally I'd like to have a copy of autoexec.sas in each programming folder that would be run automatically upon launch, but I"m open to other ideas.
2) How can I find out where SAS is looking for autoexec.sas when I launch the IDE? I've read the SAS documentation and tried placing an autoexec.sas in the same folder as the sas.exe, and also tried placing one in the system32 folder, neither executed upon launch. I imagine it has to do with us using a validated server environment.
Any help would be much appreciated and definitely ask if more information is needed. Thank you!
EDIT: Thank you everyone for your help. It seems like the answer is that that I can't get autoexec to do exactly what I was hoping for. I really appreciate everyone taking the time to help out!
What happens when SAS starts is that the config (.cfg) file runs first - this sets up a number of options including the location of the work area. The config file may then call the autoexec file - however this is optional and if it doesn't then there is a hierarchy of places that SAS looks for an autoexec as detailed here -> http://support.sas.com/kb/19/244.html
The simplest way around this is to either use the -autoexec option when you invoke SAS - detailed here -> http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#win-sysop-autoexec... or alternatively make sure you are calling the same config file with the -config option and include a call to the autoexec detailed here -> http://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.htm#p0a8vp7c9jpdcnn1r2...
I've always favoured the -config option as the config file sets up a lot of options and that way I can be sure they are always 100% in synch no matter how I call SAS
Thank you for the reply, I just had one follow up question:
For the autoexec option in the config file, is there a way to tell SAS to look for it in the same directory as the program? I tried setting the SASINITIALFOLDER option to "." but that just put it in the root directory of C.
If you are starting SAS by clicking an Icon then the properties of the Icon should have a command line ("target" in windows terms). You can add: -autoexec "Path\autoexec.sas" to the commands. Path would of course be your OS path to the autoexec you want to use.
You can actually use this approach with multiple shortcut icons to have different autoexecs or even configuration options.
I usually start SAS by clicking on the program specifically (or right click and run in batch). Is there a way to set up the default program so that it will automatically pass the -autoexec option? I tried creating a shortcut that had the option and then making that the default file association but then in that case the right click context menu becomes less useful (i.e. no batch mode option).
Thanks!
As far as I know there isn't an easy way to do this - you might be able to achieve it by editing the Windows Registry (if you're feeling brave.....) in which case you might find this helpful http://support.sas.com/resources/papers/proceedings13/115-2013.pdf
It's not something I've done myself as in 30 odd years all sites I've worked on have used the multiple icons approach suggested by @ballardw - particularly as you'll generally find most teams have multiple autoexecs for e.g. different systems, client-server mode etc.
I generally avoid doing much (if anything) in my autoexec, since the autoexec doesn't travel with me when I move between SAS environments (from PC SAS to server or whatever). From what you've written, it sounds like you want project-specific block of code that would run at the beginning of every program run for that project.
I've been doing this with a %SetUP() macro that I call at the top of every program. Each project has it's own autocall macro library, and setup.sas lives there.
If you're not a macro person, you could just have %include "&ThisDir/setup.sas" at the top of each program. I use a little macro that sets THISDIR to the path to the current program as I didn't want to rely on the working directory.
That way as long as all of the .sas files are there, it works in interactive, batch, EG, studio, stored process, DI job, etc.
Yeah I've come to realize that autoexec isn't the solution I was hoping for. Even if there was a work around, it would be a lot of effort to go through to remove one line of code.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.