Executing SAS Code from PowerShell

Occasional Contributor
Posts: 7

Executing SAS Code from PowerShell

I am trying to executing SAS code in batch mode using Powershell to kick it off.  Within the powershell code we assign the code to a variable call $SAS_APPLICATION_LOCATION and the code we are trying to assign to it as shown which the version that is use in a batch file:

"C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin "E:\Propagator Import\Export PACS test data.sas" -fullstimer -ALTLOG "E:\codeshare\"

We are using the following to run the execute this job:

$ApplicationOutput = cmd /c $SAS_APPLICATION_LOCATION

We could not get it to work but we did get it work using Ping with one of our server.

Do anybody have any experience running SAS code in batch mode using PowerShell?

Thanks for your help in this matter.

Super Contributor
Posts: 398

Re: Executing SAS Code from PowerShell

Posted in reply to Bridget53


I'm only just starting to investigate this same thing, so my answer is not only belated (I only just saw your post) but half-baked as well.

Having said that, this works for me:

pushd "$env:userprofile\My Documents\My SAS Programs"

$cmd="C:\Program Files\SAS\SASFoundation\9.2\sas.exe"
$cfg="C:\Program Files\SAS\SASFoundation\9.2\nls\en\SASV9.CFG"

cmd /c " ""$cmd"" -config ""$cfg"" -sysin ""$pgm"" "

# I also tried all of these, since I do not want to use cmd /c if at all possible
# But, they do not properly set the $LastExitCode from SAS

# Start-Process "$cmd" "-config ""$cfg"" -sysin ""$pgm"" " -Wait 
# Start-Process "$cmd" "-config ""$cfg"" -sysin ""$pgm"" " -Wait -PassThru
# Start-Process "$cmd" "-config ""$cfg"" -sysin ""$pgm"" " -Wait -NoNewWindow



I've also posted here to try and get further help:  http://www.powershellcommunity.org/Forums/tabid/54/aft/7999/Default.aspx

But like I said, the above works for me.



Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation