There are a number of ways to run SAS from Powershell:

  1. Using SAS Integration Technologies (Chris Hemedinger has some great resources on this)
  2. Directly by calling sas.exe (presuming you are running on a box with a local install)
  3. Indirectly via the SAS Stored Process Web Application.
Let me explain the awesomeness of option 3:
  • 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!
For the sake of mobile readers, I’m going to split the example over three lines:
$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.

Some prerequisites:

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