<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Execute SAS Server stored procedure from PowerShell in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/501375#M497</link>
    <description>What kind of processes are we talkong about?&lt;BR /&gt;Normally automation of SAS jobs are done via a scheduler (which in turn starts a SAS batch session with the SAS program name as a parameter). This is simplified by the Search server in your configuration directory.</description>
    <pubDate>Thu, 04 Oct 2018 08:21:09 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2018-10-04T08:21:09Z</dc:date>
    <item>
      <title>Execute SAS Server stored procedure from PowerShell</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/501293#M476</link>
      <description>&lt;P&gt;Trying to automate some of our processes and we need to run some SAS processes from command line.&amp;nbsp; Since we are running our code from SAS Server, we need to use PowerShell.&amp;nbsp; I have created a script than can successfully connect to the server, but I am not able to invoke the the stored procedure.&amp;nbsp; The methods for C# or VB don't always translate exactly, so I'm having an issue trouble shooting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;==================================================================&lt;/P&gt;&lt;P&gt;# create the Integration Technologies objects&lt;BR /&gt;$objFactory&amp;nbsp;&amp;nbsp; = New-Object -ComObject SASObjectManager.ObjectFactoryMulti2&lt;BR /&gt;$objServerDef = New-Object -ComObject SASObjectManager.ServerDef&lt;BR /&gt;$objServerDef.MachineDNSName = "&amp;lt;&amp;lt;SERVERNAME&amp;gt;&amp;gt;" # SAS Workspace node&lt;BR /&gt;$objServerDef.Port&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 8561&amp;nbsp; # workspace server port&lt;BR /&gt;$objServerDef.Protocol&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # 2 = IOM protocol&lt;BR /&gt;# Class Identifier for SAS Workspace (or some other ID)&lt;BR /&gt;$objServerDef.ClassIdentifier = "&amp;lt;&amp;lt;CLASSID&amp;gt;&amp;gt; "&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # create and connect to the SAS session&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $objSAS = $objFactory.CreateObjectByServer(&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "SASApp",&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # server name&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $true,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $objServerDef,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # built server definition&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "",&amp;nbsp;&amp;nbsp; # user ID&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ""&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # password&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Write-Host "Connected to " $objServerDef.MachineDNSName&lt;BR /&gt;}&lt;BR /&gt;catch [system.exception]&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; Write-Host "Could not connect to SAS session: " $_.Exception.Message&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;# local directory for downloaded file&lt;BR /&gt;$localPath = "c:\data"&lt;/P&gt;&lt;P&gt;# program to run&lt;BR /&gt;$program = "proc STP PROGRAM=`"/FOLDER/PROCEDURENAME`"; run;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# run the program&lt;BR /&gt;$objSAS.LanguageService.Submit($program);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$objSAS.Close()&lt;/P&gt;&lt;P&gt;==============================================================&lt;/P&gt;&lt;P&gt;I'm getting the following error:&lt;/P&gt;&lt;P&gt;You cannot call a method on a null-valued expression.&lt;BR /&gt;At F:\Testautomate.ps1:44 char:1&lt;BR /&gt;+ $objSAS.LanguageService.Submit($program);&lt;BR /&gt;+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : InvalidOperation: (:) [], RuntimeException&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : InvokeMethodOnNull&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if there is a better way or if I'm missing something here.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 22:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/501293#M476</guid>
      <dc:creator>MGOutside</dc:creator>
      <dc:date>2018-10-03T22:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: Execute SAS Server stored procedure from PowerShell</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/501375#M497</link>
      <description>What kind of processes are we talkong about?&lt;BR /&gt;Normally automation of SAS jobs are done via a scheduler (which in turn starts a SAS batch session with the SAS program name as a parameter). This is simplified by the Search server in your configuration directory.</description>
      <pubDate>Thu, 04 Oct 2018 08:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/501375#M497</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-10-04T08:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Execute SAS Server stored procedure from PowerShell</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/501521#M526</link>
      <description>&lt;P&gt;Our process is to process data in SQL Server, then at a certain step we want our work in SAS to be done.&amp;nbsp; We are using Alteryx for the work flow and we want to kick off SAS at a certain point...&amp;nbsp; Hence we are trying to put a powershell script to kick off the server level SAS stored procedure.&amp;nbsp; I cannot seem to submit or activate the process...&amp;nbsp; I have also tried assiging the StoredProcessService as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# run the program&lt;BR /&gt;$objProc = $objSAS.LanguageService.StoredProcessService;&lt;BR /&gt;$objProc.Repository = $repository&lt;BR /&gt;$objProc.Execute($procedure)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Defining the variables I get the following error:&lt;/P&gt;&lt;P&gt;Property 'Repository' cannot be found on this object; make sure it exists and is settable.&lt;BR /&gt;At F:\Testautomate2.ps1:45 char:1&lt;BR /&gt;+ $objProc.Repository = $repository&lt;BR /&gt;+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : InvalidOperation: (:) [], RuntimeException&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : PropertyNotFound&lt;/P&gt;&lt;P&gt;You cannot call a method on a null-valued expression.&lt;BR /&gt;At F:\Testautomate2.ps1:46 char:1&lt;BR /&gt;+ $objProc.Execute($procedure)&lt;BR /&gt;+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : InvalidOperation: (:) [], RuntimeException&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : InvokeMethodOnNull&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help activating the stored procedure using Powershell would be appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 15:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/501521#M526</guid>
      <dc:creator>MGOutside</dc:creator>
      <dc:date>2018-10-04T15:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: Execute SAS Server stored procedure from PowerShell</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/502045#M603</link>
      <description>Not clear why you are exploiting SAS Stored Process for this task. As said, SASBatchServer would be my primary choice.</description>
      <pubDate>Fri, 05 Oct 2018 20:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/502045#M603</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-10-05T20:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: Execute SAS Server stored procedure from PowerShell</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/502445#M672</link>
      <description>&lt;P&gt;Odd you want me to use your solution.&amp;nbsp; Suffice it to say, it will not work as we have other processes on other platforms that are not timed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you only offer this as a solution, no need to reply again.&amp;nbsp; I need to get this to work as I am trying, so if this is a server setting that I need to get our IT team to modify or if I am invoking this incorrectly please let me know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 16:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/502445#M672</guid>
      <dc:creator>MGOutside</dc:creator>
      <dc:date>2018-10-08T16:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Execute SAS Server stored procedure from PowerShell</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/502448#M673</link>
      <description>&lt;P&gt;Is it just the call to PROC STP that is not working? Why not just start with some simpler SAS code first to make sure that you can actually connect to SAS?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 16:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/502448#M673</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-08T16:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: Execute SAS Server stored procedure from PowerShell</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/502454#M675</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;- it looks like you might not have successfully connected to the SAS Workspace, as maybe the LanguageService property is null and that's what is causing the exception.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should be able to use the PowerShell ISE on your desktop&lt;A href="https://docs.microsoft.com/en-us/powershell/scripting/core-powershell/ise/how-to-debug-scripts-in-windows-powershell-ise?view=powershell-6" target="_self"&gt; to help debug your PowerShell script&lt;/A&gt; and see a bit of what's going on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 17:00:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-SAS-Server-stored-procedure-from-PowerShell/m-p/502454#M675</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2018-10-08T17:00:50Z</dc:date>
    </item>
  </channel>
</rss>

