There are a number of ways to run SAS from Powershell:
- Using SAS Integration Technologies (Chris Hemedinger has some great resources on this)
- Directly by calling sas.exe (presuming you are running on a box with a local install)
- Indirectly via the SAS Stored Process Web Application.
- It deals with authentication (no need for embedded passwords)
- Can perform tasks using system account (sassrv), as SAS code is secured server-side
- Resource management (no need to tidy up any redundant sessions)
- Can be done in just ONE LINE of Powershell code!
$uri=“http://YOURSERVER.YOURDOMAIN:8080/SASStoredProcess/do”$pgm=“/Products/SAS Intelligence Platform/Samples/Sample: Hello World”invoke-webrequest -Uri “$($uri)?_program=$pgm“ -UseDefaultCredentials
Which gives the response:
The key part to this request, to avoid HTTP Status 401 and “This request requires HTTP authentication” response, is the -UseDefaultCredentials parameter. This uses the account that Powershell is running in, to connect to the server.
- You need to configure your SAS code to run inside a Stored Process using SAS Management Console – set for streaming output
- You may need to set your execution policy (explained here)
- The account being used to run the script must have a SAS identity, and the web server must be configured for single signon.