BookmarkSubscribeRSS Feed
mathias
Quartz | Level 8

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,

6 REPLIES 6
milts
Pyrite | Level 9

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

Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
milts
Pyrite | Level 9

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

mathias
Quartz | Level 8

@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...

milts
Pyrite | Level 9

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2738 views
  • 3 likes
  • 4 in conversation