Executing SAS Code from PowerShell

Reply
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: 387

Re: Executing SAS Code from PowerShell

Posted in reply to Bridget53

Hi,

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"
$pgm="test1.sas"

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

"LastExitCode=$LastExitCode"

popd

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.

Regards,

Scott

Ask a Question
Discussion stats
  • 1 reply
  • 1337 views
  • 0 likes
  • 2 in conversation