BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
elisehoo1
Obsidian | Level 7

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. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
AllanBowe
Barite | Level 11

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:

 

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs

View solution in original post

16 REPLIES 16
sbxkoenk
SAS Super FREQ

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

Tom
Super User Tom
Super User

That article does NOT show how you would implement an autoexec.sas functionality.

elisehoo1
Obsidian | Level 7

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


 

 

AllanBowe
Barite | Level 11

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:

 

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
Tom
Super User Tom
Super User

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.

AllanBowe
Barite | Level 11
You can control the context used for running jobs via the "_contextname" URL parameter in the SASJobExecution web app.

It's worth noting that in most enterprise SAS 9 deployments, the autoexec (eg autoexec_usermods.sas) file is also typically locked to those with admin rights.
/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
Tom
Super User Tom
Super User

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.

 

AllanBowe
Barite | Level 11
Doesn't have to be a URL param - it can also be passed in under "parameters" in the input JSON to the REST APIs (here's an example for the SASjs adapter: https://github.com/sasjs/adapter/blob/0aa0ae65e0cae3564177ba105ad90b73edf9073a/src/SASViyaApiClient.... )


The thing with Viya is that all requests are going through either the REST API, or through the job execution web service. The CLI (eg the SASjs CLI or the official SAS CLIs) are just wrappers for making those requests.

In reference to "normal command line SAS call", this isn't really a thing any more. It IS possible to invoke the SAS exe from a Viya server, but that's really just a SAS 9 session, it's not "Viya aware" insofar as you can trigger viya services from SAS code without extra authentication etc..
/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
Tom
Super User Tom
Super User

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 ? 

AllanBowe
Barite | Level 11
The only places in Viya that I know of, where you can set up an "automatic" autoexec, are:

* The compute contexts (eg SAS Studio, SAS Job Execution). This is the 'official', 'system' autoexec.
* The "user autoexec" in SAS Studio, this is user-specific and not useful for batch jobs.

Beyond that it's a case of running precode as part of your code, somehow. Maybe someone here, more knowledgeable, can correct me. I don't see any other options in the REST API.

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
elisehoo1
Obsidian | Level 7

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

 

elisehoo1_0-1621173954809.png

 

cheers

 

 

 

Tom
Super User Tom
Super User

Those are configuration files are for ALL of the SAS sessions.

Which is different than how the autoexec.sas file works in normal SAS 

elisehoo1
Obsidian | Level 7
Good day Tom,

May i know what are the difference btw them ?

Thanks
Elise
Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Discussion stats
  • 16 replies
  • 4867 views
  • 11 likes
  • 4 in conversation