Hello,
Remembered we used to add few lines into autoexec (i.e ../BatchServer/autoexec(_usermods).sas.) to run some initial steps , for example, the report_date, the batch_date , compiling the macros and etc. These stuffs are very cool for us to handle the batch run for the whole intergradation .
May I know how do we do it in SAS VIYA?
Thanks.
Hi @elisehoo1
In Viya, the autoexec is stored as part of the compute context. To modify it you need to log onto SASEnvironment Manager as an administrator, select Contexts, View Compute Contexts. Choose the relevant compute context (eg for SAS Studio, or Job Execution Service), click the edit icon, then click the "Advanced" tab.
You can now enter autoexec statements and any startup options.
To help automate this process, we (Analytium SAS Apps team) built a tool that makes use of the Viya REST APIs to modify compute contexts. The benefit of this approach is that you can keep your source configuration in GIT and deploy on demand. The documentation for that is available here: https://cli.sasjs.io/context
If you don't have the administrator rights, you could also configure your jobs to include an autoexec as "precode". If you are using SASjs to compile your jobs / services / tests, you can do this via the initProgram setting. More info:
Hello,
I suppose you are running your SAS jobs in batch modus?
See this communities article:
How to Run SAS Programs in Batch in the New SAS Viya
https://communities.sas.com/t5/SAS-Communities-Library/How-to-Run-SAS-Programs-in-Batch-in-the-New-S...
It shows you how to run an autoexec in SAS VIYA 3.5 versus later VIYA .
Cheers,
Koen
That article does NOT show how you would implement an autoexec.sas functionality.
Hi @sbxkoenk
this is very useful information .it seems straight forward , just I am not sure how to create the SAS_CLI_PROFILE yet. do share the sample if any , thanks.
/opt/sas/spre/home/SASFoundation/sas -autoexec "/opt/sas/viya/config/etc/workspaceserver/default/autoexec_deployment.sas" /tmp/1.sas -log /tmp/1.log
/opt/sas/viya/home/bin/sas-viya --profile ${SAS_CLI_PROFILE} batch jobs submit-pgm --pgm-path /tmp/1.sas --context default --watch-output --wait-log-list --results-dir /tmp
Regards
Elise
Hi @elisehoo1
In Viya, the autoexec is stored as part of the compute context. To modify it you need to log onto SASEnvironment Manager as an administrator, select Contexts, View Compute Contexts. Choose the relevant compute context (eg for SAS Studio, or Job Execution Service), click the edit icon, then click the "Advanced" tab.
You can now enter autoexec statements and any startup options.
To help automate this process, we (Analytium SAS Apps team) built a tool that makes use of the Viya REST APIs to modify compute contexts. The benefit of this approach is that you can keep your source configuration in GIT and deploy on demand. The documentation for that is available here: https://cli.sasjs.io/context
If you don't have the administrator rights, you could also configure your jobs to include an autoexec as "precode". If you are using SASjs to compile your jobs / services / tests, you can do this via the initProgram setting. More info:
With traditional SAS execution the users could use the autoexec.sas to control the setup of the SAS environment that the code would run in. So you could create a project folder and configure the autoexec.sas file to setup things like librefs, filerefs, macro variables and then run a generic SAS program.
It sounds like the equivalent in this structure is to create different Compute Context settings. And then run a different command line call to invoke a different Compute Context when you run your SAS program.
So perhaps instead of an autoexec.sas program in the project directory you would need to create a shell script that will be used to batch run the SAS programs in the proper context.
But it does look like the individual user has lost the ability to control the context that their SAS programs run in.
They either need to have administrator access to create new compute context settings or add startup code to every program that they want to run.
Not sure how URLs come into command line execution of SAS programs, but yeah it looks like it should be possible in someway to pass the context identifier as part of the command.
I have never had to use autoexec_usermods.sas files, but it looks to me like they are just part of the context configuration and not really the same thing as an autoexec.sas file in a normal command line SAS call.
We have come full circle back to how to implement the functionality of autoexec.sas for Viya (or for that matter any "enterprise" installation of SAS).
With an autoexec.sas program you could issue a command to run SAS program myreport.sas and essentially you are really asking it to run (autoexec.sas + myreport.sas).
Is there an equivalent with Viya? Perhaps the implantation is not a text file of SAS statement. Perhaps it is some other JSON object that you send along with your request to run myreport.sas ?
I tried this and it seems working well for both sas studio and sas job flow/
i added my necessary setup in sasv9_usermodes and autoexec_usermodes.
https://documentation.sas.com/doc/en/calcdc/3.5/calsrvpgm/n08002viyaprgmsrvs00000admin.htm
cheers
Those are configuration files are for ALL of the SAS sessions.
Which is different than how the autoexec.sas file works in normal SAS
The configuration has to be set before SAS even starts and so impacts every SAS job.
The autoexec was typically something a user could do to set the environment for the current job they are running (with the limitation that configuration options cannot change). On a multi-user environment different users might want to have different things run before their programs run. On even in a single user environment the user might be working on different projects that require different settings. As long as those changes did not involve configuration settings users were free to create as many different environments are they wanted without having to get "systems admin" involved.
So I made have a standard program to do analysis. And then multiple different projects that required that analysis. I could set the details for the project into the autoexec.sas file and now the same program and be run unmodified for multiple projects.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!