Search Order to find Autoexec file

Reply
Contributor
Posts: 43

Search Order to find Autoexec file

Hi All,

As per the information provided on SAS website the search order to find the autoexec file is

The Default Autoexec File

Unlike the configuration file, a SAS autoexec file is not required in order to run SAS. But, if you do have an autoexec file, the default name is AUTOEXEC.SAS. SAS uses the following search order to find the AUTOEXEC.SAS file:

  1. Search the current folder.Note:   For information on determining the current folder, see: Determining the Current Folder When SAS Starts[cautionend]
  2. Search the paths that are specified by the Windows PATH environment variable.
  3. Search the root folder of the current drive.
  4. Search the folder that contains the SAS.EXE file.

If an AUTOEXEC.SAS file is not present in one of these folders and if you did not specify the -AUTOEXEC option on the command line or within any of your configuration files, then SAS assumes that there is no autoexec file to process. For more information, see AUTOEXEC System Option: Windows.


But when I start my SAS session, the default autoexec.sas in SAS root folder is invoked even though there is a customized autoexec in the folder from where the SAS is invoked. Can anyone help me out why is it so.


Thanks


Trusted Advisor
Posts: 1,615

Re: Search Order to find Autoexec file

But when I start my SAS session, the default autoexec.sas in SAS root folder is invoked even though there is a customized autoexec in the folder from where the SAS is invoked. Can anyone help me out why is it so.

Are you sure you have the correct folder "where the SAS is invoked"?? Which of the items in the list 1 thru 4 that you quoted is what you mean by "where the SAS is invoked"? If by this you mean item 4 in the search order, then SAS will not find your customized autoexec, it will use the default.

I always use the -AUTOEXEC option to point SAS to the exact AUTOEXEC file I want SAS to use, and then there's really no issue about search order.

Contributor
Posts: 43

Re: Search Order to find Autoexec file

Hi Paige,

Say if I have a folder 'test' with some .sas programs including an autoexec.sas, when I open one of those programs the autoexec from the root folder is processed instead of the autoexec in 'test' folder.

Thanks

Respected Advisor
Posts: 3,890

Re: Search Order to find Autoexec file

The "root folder" depends on how SAS starts up and not from where you load your .sas files for execution.

Valued Guide
Posts: 2,175

Re: Search Order to find Autoexec file

This might be the reason SAS launches in a different folder than you expect.

Double clicking a .sas program seemed to start base SAS in the c:\windows\system32 folder.

When I launched SAS from a launch icon or start-menu, the "start -in" folder is pre-defined and probably not windows\system32. Windows launched SAS to open rhe selected sas program, using an "ole automation server" which seemed to follow rules I couldn't control.

of course your experience might be different

good luck

peterC

support.sas.com/resources/papers/proceedings13/472-2013.pdf

Super User
Super User
Posts: 6,500

Re: Search Order to find Autoexec file

Two issues I see.

1) Are you sure that the current directory is what you think it is?  Trying running a little program like this and see if it works.

data _null_;

  infile 'autoexec.sas';

  input;

  put _infile_;

run;

2) Are you sure that SAS is NOT being invoked with the -AUTOEXEC option on the command line OR in the config settings?

Contributor
Posts: 43

Re: Search Order to find Autoexec file

Hi Tom,

1) Are you sure that the current directory is what you think it is?  Trying running a little program like this and see if it works.

data _null_;

  infile 'autoexec.sas';

  input;

  put _infile_;

run;

When I open a sas program in folder x the log says the following

NOTE: AUTOEXEC processing beginning; file is D:\Program

      Files\SASHome\SASFoundation\9.3\autoexec.sas.

and when I run the code you sent, the log outputs the autoexec which is in folder x

2) Are you sure that SAS is NOT being invoked with the -AUTOEXEC option on the command line OR in the config settings?


Yes, I did check the command line and config settings and neither of them has -AUTOEXEC option.


Thanks


Super Contributor
Posts: 287

Re: Search Order to find Autoexec file

I have same problem. The autoexec file in the folder containing the sas.exe is used even though I have an autoexec file in my current folder. The current folder is apparently correct (shown in bottom of the SAS window), and also shown when I run the code suggested by Tom.

If I use the -autoexec option in the cfg file, then I can get sas to run the correct autoexec file. But that will not work, since it will give errors for those users who have no autoexec-file.

Super User
Posts: 6,936

Re: Search Order to find Autoexec file

Inspect the desktop link (icon) and see from which directory SAS is run.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Respected Advisor
Posts: 3,890

Re: Search Order to find Autoexec file

I feel it's a good idea to have a general autoexec.sas and autoexec_usermods.sas to invoke an environment which is the same for everybody. If you are the admin then you can always define an additional folder location where users can have an additional personal autoexex as well (.../path/&sysuserid/autoexec_usermods.sas).

You then can add some macro code to the general autoexec_usermods.sas where you check for existence of the user specific autoexec - and if it exists you %include it and process it as well as part of SAS invocation.

This allows you also to decide in which sequence the autoexec's get executed and which general autoexec settings you want to allow a user to overwrite (process before user specific autoexec) and which one not (process after user specific autoexec).

Super Contributor
Posts: 287

Re: Search Order to find Autoexec file

I think it is correct that the "start in" is the one determine the location of the where SAS looks for the autoexec - not the initial folder.

The I have used the solution suggested by Patrick. That is, I made an autoexec where sas.exe is located, and in this I have the macro below that allow users to have their own autoexec file.

%macro runautoexec;

%if %sysfunc(fileexist(d:\users\&sysuserid.\autoexec.sas)) %then %do;

    %include "d:\users\&sysuserid.\autoexec.sas";

%put Your autoexec file "d:\users\&sysuserid.\autoexec.sas" is executed;

%end;

%mend;

%runautoexec;

Super User
Posts: 6,936

Re: Search Order to find Autoexec file

To avoid confusion with a "standard" autoexec.sas, I set the name for such a file as egauto.sas and put the following into the autoexec_usermods file for the workspace server:

%macro indiv_start;

%if %sysfunc(fileexist('$HOME/egauto.sas')) %then %do;

%put Run egauto.sas;

%inc '$HOME/egauto.sas';

%end;

%mend;

This is of course UNIX syntax, so it needs to be adapted for Windows.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 287

Re: Search Order to find Autoexec file

I found out how to itSmiley Happy

It is correct that it is the "start in" option that determines the first place SAS looks for an autoexecfile. Then if I put a shortcut in the "C:\users\public\public desktop" and specify the path containing the environment variable %user%, then SAS looks directly in the users folder. And this does not need to be the same as the users profile folder which is the default.

Ask a Question
Discussion stats
  • 12 replies
  • 412 views
  • 1 like
  • 7 in conversation