Your SAS programs, embedded in web apps and elsewhere

autoexec code stored process

Reply
Frequent Contributor
Posts: 127

autoexec code stored process

Hi,

Where do I need to put sas code that will be common to all stored processes ?

(need to be executed before each stored process)

Thanks,

Super Contributor
Posts: 349

Re: autoexec code stored process

Super Contributor
Posts: 326

Re: autoexec code stored process

Hi,

Other option you can do is to create a sas file wherein you put all the codes that you want to be executed prior to running stored procs.

After that you need to go to SMC, on the properties->options of the stored procses definition and add the -autoexec parameter on the execution command.

Just curious, what are you planning to put on the autoexec which needs to execute prior to your stored processes? libnames? admin table logging?

Hope this helps,

Milton

PROC Star
Posts: 1,322

Re: autoexec code stored process

Hi Milton,

I knew you could specify an autoexec at the server level, but are you saying that you can specify an autoexec at the stored process level (i.e. a different autoexec for different stored processes)?  I've been hoping to do that, but haven't been able to see how it could be done (I'm not an admin on the server, so may not be seeing all that is possible).  So now I just start a stored process definition by %including an autoexec.

I'm not seeing where I can specify an autoexec for a stored process in SMC:

SPopt.bmp

Thanks,

--Q.

Super Contributor
Posts: 326

Re: autoexec code stored process

Hi Q,

The one I know and was saying on my previous post is a universal one. Meaning that for everytime a stored process is executed, it executes the autoexec file specified first. I was also hoping that they have a feature similar on what you want. Smiley Happy

Sorry, but with your requirement I think there's currently no way to have different autoexecs depending on the stored proc to execute except for your current approach which is the use of %include.

Milton

Frequent Contributor
Posts: 127

Re: autoexec code stored process

@milts

> "Just curious, what are you planning to put on the autoexec which needs to execute prior to your stored processes? libnames? admin table logging?"

I wanted to define macros, formats and a template

I figured how to store the macros in a sasmacr catalog but the problem remains the same, I have to declare the sasmstore at the beginning of every project flow or stored process:

"options mstored sasmstore=common ;"

And since this is locking the catalog, I now also have to use this hack at the end of every project flow or stored process:

http://support.sas.com/kb/9/807.html

/* HACK TO REALEASE LOCK ON MACROS.SASMACR.CATALOG */

  * get the current value of the SASMSTORE option ;

  %let mstorelib=%sysfunc(getoption(sasmstore));

  * assign a temp libref to the path of the work library ;

  libname temp "%sysfunc(pathname(work))" access=temp;

  * assign the temp library to the SASMSTORE option ;

  options mstored sasmstore=temp;

  * compile and store dummy macro ;

  %macro foo /store;

  %mend;

  * reset the SASMSTORE option to the original value ;

  options mstored sasmstore=&mstorelib;

would like not having to copy paste it everywhere...

Super Contributor
Posts: 326

Re: autoexec code stored process

Hi Mathias,

If that's the case for you then you can try what I was saying assuming that you want that piece of code to be executed for all stored procs.

1. Put that piece of code on a separate .sas file. (Ex. myautoexec.sas)

2. Under SMC, Go to Server Manager -> SASMain -> Logical Stored Process Server, right click properties on the innermost one.

3. Under the Options tab, you should see the Command item there, I think by default this is the value there:

sas -config "C:\SAS\MyPlan\Lev1\SASMain\StoredProcessServer\sasv9_StorProcSrv.cfg"

then add here your autoexec file, so it would go something like this:

sas -config "C:\SAS\MyPlan\Lev1\SASMain\StoredProcessServer\sasv9_StorProcSrv.cfg" - autoexec <path>\myautoexec.sas

4. Restart your SAS Services, then try to check run a stored proc and see it works.

Hope this helps,

Milton

smc.png

Ask a Question
Discussion stats
  • 6 replies
  • 945 views
  • 3 likes
  • 4 in conversation