<?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: Run a procedure with parameters from Excel or with a VBscript in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-a-procedure-with-parameters-from-Excel-or-with-a-VBscript/m-p/45451#M5210</link>
    <description>Very impressive!&lt;BR /&gt;
&lt;BR /&gt;
I'm definitely going to keep this in my back pocket; I know it'll come in handy someday.&lt;BR /&gt;
&lt;BR /&gt;
Tom</description>
    <pubDate>Wed, 08 Dec 2010 23:15:48 GMT</pubDate>
    <dc:creator>TomKari</dc:creator>
    <dc:date>2010-12-08T23:15:48Z</dc:date>
    <item>
      <title>Run a procedure with parameters from Excel or with a VBscript</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-a-procedure-with-parameters-from-Excel-or-with-a-VBscript/m-p/45448#M5207</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
I want to run an EG procedure from Excel. I'm trying to launch it with a vbscript. Sas is able to generate the code to run it but my procedure contains parameters that are prompted when the proc is runned manually (these parameters (year, month and date) are needed in some queries).&lt;BR /&gt;
&lt;BR /&gt;
Unfortunatly when the script runs, the parameters are not prompt.&lt;BR /&gt;
I can prompt informations from the script but I don't know how to run the procedure with this informations as parameters for the procedure.&lt;BR /&gt;
&lt;BR /&gt;
Here is my code :&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Option Explicit&lt;BR /&gt;
Dim app ' As SASEGuide.Application&lt;BR /&gt;
dim a ' as integer&lt;BR /&gt;
dim b ' as integer&lt;BR /&gt;
dim c ' as integer&lt;BR /&gt;
&lt;BR /&gt;
a= InputBox("Jour")&lt;BR /&gt;
b= InputBox("Mois")&lt;BR /&gt;
c= InputBox("Année")&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Call dowork (a,b,c)&lt;BR /&gt;
&lt;BR /&gt;
'shut down the app&lt;BR /&gt;
If not (app Is Nothing) Then&lt;BR /&gt;
app.Quit&lt;BR /&gt;
Set app = Nothing&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Sub dowork(a,b,c)&lt;BR /&gt;
On Error Resume Next&lt;BR /&gt;
'----&lt;BR /&gt;
' Start up Enterprise Guide using the project name&lt;BR /&gt;
'----&lt;BR /&gt;
Dim prjName ' As String&lt;BR /&gt;
Dim prjObject ' As SASEGuide.Project&lt;BR /&gt;
Dim containerName ' As String&lt;BR /&gt;
Dim containerObject ' As SASEGuide.Container&lt;BR /&gt;
Dim containerColl ' As SASEGuide.ContainerCollection&lt;BR /&gt;
Dim annee ' As integer&lt;BR /&gt;
Dim mois' As integer&lt;BR /&gt;
Dim jour' As integer&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
prjName = "\\xxxxxxxxx.egp" ' Project Name&lt;BR /&gt;
containerName = "Flux de processus" ' Container Name&lt;BR /&gt;
&lt;BR /&gt;
Set app = CreateObject("SASEGObjectModel.Application.4")&lt;BR /&gt;
If Checkerror("CreateObject") = True Then&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
Set prjObject = app.Open(prjName,"")&lt;BR /&gt;
If Checkerror("App.Open") = True Then&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
'-----&lt;BR /&gt;
'Get The Container Collection and Object&lt;BR /&gt;
'----- &lt;BR /&gt;
Set containerColl = prjObject.ContainerCollection&lt;BR /&gt;
If Checkerror("Project.ContainerCollection") = True Then&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
Dim i ' As Long&lt;BR /&gt;
Dim count ' As Long&lt;BR /&gt;
count = containerColl.count&lt;BR /&gt;
For i = 0 To count&lt;BR /&gt;
Set containerObject = containerColl.Item(i)&lt;BR /&gt;
If Checkerror("ContainerCollection.Item") = True Then&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
If (containerObject.Name = containerName) Then&lt;BR /&gt;
Exit For&lt;BR /&gt;
Else&lt;BR /&gt;
Set containerObject = Nothing&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
Next &lt;BR /&gt;
&lt;BR /&gt;
If not (containerObject Is Nothing) Then&lt;BR /&gt;
'----&lt;BR /&gt;
' Run the Container&lt;BR /&gt;
'----&lt;BR /&gt;
containerObject.Run &lt;BR /&gt;
If Checkerror("Container.Run") = True Then&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
End If &lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
'-----&lt;BR /&gt;
' Save the new project&lt;BR /&gt;
'-----&lt;BR /&gt;
prjObject.Save&lt;BR /&gt;
If Checkerror("Project.Save") = True Then&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
'-----&lt;BR /&gt;
' Close the project&lt;BR /&gt;
'-----&lt;BR /&gt;
prjObject.Close&lt;BR /&gt;
If Checkerror("Project.Close") = True Then&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Function Checkerror(fnName)&lt;BR /&gt;
Checkerror = False&lt;BR /&gt;
&lt;BR /&gt;
Dim strmsg ' As String&lt;BR /&gt;
Dim errNum ' As Long&lt;BR /&gt;
&lt;BR /&gt;
If Err.Number 0 Then&lt;BR /&gt;
strmsg = "Error #" &amp;amp; Hex(Err.Number) &amp;amp; vbCrLf &amp;amp; "In Function " &amp;amp; fnName &amp;amp; vbCrLf &amp;amp; Err.Description&lt;BR /&gt;
'MsgBox strmsg 'Uncomment this line if you want to be notified via MessageBox of Errors in the script.&lt;BR /&gt;
Checkerror = True&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
End Function&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thank you for your help&lt;BR /&gt;
&lt;BR /&gt;
Georges</description>
      <pubDate>Tue, 07 Dec 2010 09:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-a-procedure-with-parameters-from-Excel-or-with-a-VBscript/m-p/45448#M5207</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-12-07T09:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Run a procedure with parameters from Excel or with a VBscript</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-a-procedure-with-parameters-from-Excel-or-with-a-VBscript/m-p/45449#M5208</link>
      <description>Very interesting idea!&lt;BR /&gt;
&lt;BR /&gt;
I don't have a "good" solution, but here are a couple of workaround suggestions.&lt;BR /&gt;
&lt;BR /&gt;
1. I'm pretty sure you can put your parameters into environment variables in VBScript. You could then retrieve them into SAS code using the sysget SAS function.&lt;BR /&gt;
&lt;BR /&gt;
2. Even more kludgy; write the values to a parameter file, and then read the parameter file in SAS.&lt;BR /&gt;
&lt;BR /&gt;
I hope somebody comes up with a more elegant solution than these!&lt;BR /&gt;
&lt;BR /&gt;
Bonne chance,&lt;BR /&gt;
  Tom</description>
      <pubDate>Wed, 08 Dec 2010 02:34:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-a-procedure-with-parameters-from-Excel-or-with-a-VBscript/m-p/45449#M5208</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2010-12-08T02:34:31Z</dc:date>
    </item>
    <item>
      <title>Re: Run a procedure with parameters from Excel or with a VBscript</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-a-procedure-with-parameters-from-Excel-or-with-a-VBscript/m-p/45450#M5209</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
If anyone is interested, I found what I need in another forum (I forgot to keep the link for reference, sorry). &lt;BR /&gt;
The main idea is to open the project in background without running it, defining the parameters and the run it.&lt;BR /&gt;
My code now look like that :&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
Dim app         ' As SASEGuide.Application&lt;BR /&gt;
Dim j ' as integer&lt;BR /&gt;
Dim m ' as integer&lt;BR /&gt;
Dim a ' as integer&lt;BR /&gt;
&lt;BR /&gt;
j = InputBox("Jour")&lt;BR /&gt;
m = InputBox("Mois")&lt;BR /&gt;
a = InputBox("Année")&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Call dowork(j, m, a)&lt;BR /&gt;
&lt;BR /&gt;
'shut down the app&lt;BR /&gt;
If Not (app Is Nothing) Then&lt;BR /&gt;
    app.Quit&lt;BR /&gt;
    Set app = Nothing&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Sub dowork(j, m, a)&lt;BR /&gt;
    On Error Resume Next&lt;BR /&gt;
    '----&lt;BR /&gt;
    ' Start up Enterprise Guide using the project name&lt;BR /&gt;
    '----&lt;BR /&gt;
    Dim prjName     ' As String&lt;BR /&gt;
    Dim prjObject   ' As SASEGuide.Project&lt;BR /&gt;
    Dim containerName     ' As String&lt;BR /&gt;
    Dim containerObject   ' As SASEGuide.Container&lt;BR /&gt;
    Dim containerColl     ' As SASEGuide.ContainerCollection&lt;BR /&gt;
    Dim annee ' As integer&lt;BR /&gt;
    Dim mois ' As integer&lt;BR /&gt;
    Dim jour ' As integer&lt;BR /&gt;
    Dim parmList&lt;BR /&gt;
    Dim parm&lt;BR /&gt;
    Dim parm2&lt;BR /&gt;
    Dim parm3&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
    prjName = "\\myfolder\myfile.egp" ' Project Name&lt;BR /&gt;
      &lt;BR /&gt;
    Set app = CreateObject("SASEGObjectModel.Application.4")&lt;BR /&gt;
    If Checkerror("CreateObject") = True Then&lt;BR /&gt;
        Exit Sub&lt;BR /&gt;
    End If&lt;BR /&gt;
    &lt;BR /&gt;
    Set prjObject = app.Open(prjName, "")&lt;BR /&gt;
    If Checkerror("App.Open") = True Then&lt;BR /&gt;
        Exit Sub&lt;BR /&gt;
    End If&lt;BR /&gt;
    &lt;BR /&gt;
    '---&lt;BR /&gt;
    ' discover the parameters&lt;BR /&gt;
    '---&lt;BR /&gt;
    Set parmList = prjObject.Parameters&lt;BR /&gt;
    WScript.Echo "Project has " &amp;amp; parmList.count &amp;amp; " parameters."&lt;BR /&gt;
    &lt;BR /&gt;
    ' work with the first parameter&lt;BR /&gt;
    Set parm = parmList.Item(0)&lt;BR /&gt;
'    WScript.Echo parm.Name &amp;amp; " parameter has default value of " &amp;amp; parm.DefaultValue&lt;BR /&gt;
    parm.Value = m&lt;BR /&gt;
'    WScript.Echo parm.Name &amp;amp; " parameter has been set to value of " &amp;amp; parm.Value&lt;BR /&gt;
    &lt;BR /&gt;
    ' work with the second parameter&lt;BR /&gt;
    Set parm2 = parmList.Item(1)&lt;BR /&gt;
'    WScript.Echo parm2.Name &amp;amp; " parameter has default value of " &amp;amp; parm2.DefaultValue&lt;BR /&gt;
    parm2.Value = a&lt;BR /&gt;
'    WScript.Echo parm2.Name &amp;amp; " parameter has been set to value of " &amp;amp; parm2.Value&lt;BR /&gt;
&lt;BR /&gt;
    ' work with the third parameter&lt;BR /&gt;
    Set parm3 = parmList.Item(2)&lt;BR /&gt;
'    WScript.Echo parm3.Name &amp;amp; " parameter has default value of " &amp;amp; parm3.DefaultValue&lt;BR /&gt;
    parm3.Value = j&lt;BR /&gt;
'    WScript.Echo parm3.Name &amp;amp; " parameter has been set to value of " &amp;amp; parm3.Value&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
    '---------&lt;BR /&gt;
    ' run the project&lt;BR /&gt;
    '---------&lt;BR /&gt;
    prjObject.Run&lt;BR /&gt;
        &lt;BR /&gt;
'    WScript.Echo parm.Name &amp;amp; " parameter has been set after Run to value of " &amp;amp; parm.Value&lt;BR /&gt;
'    WScript.Echo parm2.Name &amp;amp; " parameter has been set after Run to value of " &amp;amp; parm2.Value&lt;BR /&gt;
'    WScript.Echo parm3.Name &amp;amp; " parameter has been set after Run to value of " &amp;amp; parm3.Value&lt;BR /&gt;
&lt;BR /&gt;
    prjObject.Close&lt;BR /&gt;
    app.Quit&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Function Checkerror(fnName)&lt;BR /&gt;
    Checkerror = False&lt;BR /&gt;
    &lt;BR /&gt;
    Dim strmsg      ' As String&lt;BR /&gt;
    Dim errNum      ' As Long&lt;BR /&gt;
    &lt;BR /&gt;
    If Err.Number &amp;lt;&amp;gt; 0 Then&lt;BR /&gt;
        strmsg = "Error #" &amp;amp; Hex(Err.Number) &amp;amp; vbCrLf &amp;amp; "In Function " &amp;amp; fnName &amp;amp; vbCrLf &amp;amp; Err.Description&lt;BR /&gt;
        'MsgBox strmsg  'Uncomment this line if you want to be notified via MessageBox of Errors in the script.&lt;BR /&gt;
        Checkerror = True&lt;BR /&gt;
    End If&lt;BR /&gt;
         &lt;BR /&gt;
End Function&lt;/B&gt;</description>
      <pubDate>Wed, 08 Dec 2010 09:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-a-procedure-with-parameters-from-Excel-or-with-a-VBscript/m-p/45450#M5209</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-12-08T09:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Run a procedure with parameters from Excel or with a VBscript</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-a-procedure-with-parameters-from-Excel-or-with-a-VBscript/m-p/45451#M5210</link>
      <description>Very impressive!&lt;BR /&gt;
&lt;BR /&gt;
I'm definitely going to keep this in my back pocket; I know it'll come in handy someday.&lt;BR /&gt;
&lt;BR /&gt;
Tom</description>
      <pubDate>Wed, 08 Dec 2010 23:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-a-procedure-with-parameters-from-Excel-or-with-a-VBscript/m-p/45451#M5210</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2010-12-08T23:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Run a procedure with parameters from Excel or with a VBscript</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-a-procedure-with-parameters-from-Excel-or-with-a-VBscript/m-p/45452#M5211</link>
      <description>There are lots of other examples of SAS Enterprise Guide automation scripts at:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/40/781.html" target="_blank"&gt;http://support.sas.com/kb/40/781.html&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Chris</description>
      <pubDate>Thu, 09 Dec 2010 13:36:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Run-a-procedure-with-parameters-from-Excel-or-with-a-VBscript/m-p/45452#M5211</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2010-12-09T13:36:45Z</dc:date>
    </item>
  </channel>
</rss>

