Hello,
I am trying to find the best solution for executing a powershell script from a sas program. I have found a few articles that discuss pulling information into SAS EG with powershell or calling SAS EG jobs using powershell but I have not seen anything that will show me how to execute a powershell command to run a script.
Any help would be appreciated.
Ok, I figured it out by pieceing some articles I found together.
Within a SAS program, insert the following code.
%let machine = pp7h56j082; /* Machine name with admin privledges */
x 'C:\Windows\syswow64\Windowspowershell\v1.0\powershell.exe' -file "L:\Powershell Files\PrintFromExcelToPDF.ps1" &machine;
The Macro sets the machine name that has administrator permissions in order to call the powershell commands in the .ps1 file. The remaining code opens powershell via windows command and passes in the powershell command to execute the powershell script needed.
Hope this helps others!
Ok, I figured it out by pieceing some articles I found together.
Within a SAS program, insert the following code.
%let machine = pp7h56j082; /* Machine name with admin privledges */
x 'C:\Windows\syswow64\Windowspowershell\v1.0\powershell.exe' -file "L:\Powershell Files\PrintFromExcelToPDF.ps1" &machine;
The Macro sets the machine name that has administrator permissions in order to call the powershell commands in the .ps1 file. The remaining code opens powershell via windows command and passes in the powershell command to execute the powershell script needed.
Hope this helps others!
Your code is not syntactically correct.
- there is a missing single quote to close the command string
- single quotes prevent the resolution of the macro variable
Thanks @Kurt_Bremser. It was a typo in my code but it seemed to work anyway. I have corrected the code and the post above. I appreciate the heads up!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.