BookmarkSubscribeRSS Feed
slacey
Obsidian | Level 7

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!

8 REPLIES 8
ChrisBrooks
Ammonite | Level 13

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

 

 

slacey
Obsidian | Level 7

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.

ballardw
Super User

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.

slacey
Obsidian | Level 7

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!

ChrisBrooks
Ammonite | Level 13

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.

ChrisBrooks
Ammonite | Level 13
You could reference the SASROOT environment variable in your path but I’d strongly recommend against it. The SASROOT location can be overwritten by a hot fix or service pack. Generally people keep their autoexec files somewhere else for this reason.
Quentin
Super User

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.  

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
slacey
Obsidian | Level 7

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1778 views
  • 5 likes
  • 4 in conversation