BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
luizcbarrosaf
Fluorite | Level 6

I want to change the code below, so that it executes the sas guide project (.egp) and changes the parameter value according to the values of the array. (The idea is to open the project, run to the value of the array (0), close the project; open the project, run to the value array (1); ... until the array (n)).

 

But it executes only for the first value of the array, not the sequence for the other values. What's the mistake?

 

I added the line (for t = 0 to UBound (id)) and put (Next) before app.Quit..... Also change the value of parameter

parm.Value = id(t)
Dim t
Dim id

id=Array("111111111","22222222","33333333")


'-----------------------------------

' The name and location of the project file that will be opened and run by this script.
prjName = "C:\SAS\EG\Samples\XXXXX.egp" 'Project Name

for t = 0 to UBound(id)

And at the end of the code

Next
app.Quit

The full code

 

Option Explicit
'----------------------------------------------------------------
'AutomationPrompts.vbs
'This example program demonstrates how to use the 4.2 SAS Enterprise Guide
'automation interface to access and modify the prompts for a project and a stored
'process within that project.  The project is opened and the project prompt names
'and values are displayed to the user.  Subsequently, the stored processes within
'the project are opened and their prompt names and values are then displayed.
'
'The prompt value for the stored process is changed to 'M' (for male), the project
'is saved then run.
'
'The project is called AutomationwithPrompts.egp and the prjName variable should be
'modified to reflect the location of this proejct on the machine that is running
'this script.
'----------------------------------------------------------------

'--------------
'Declare the variables that will be used in the program
'--------------
Dim app
Dim prjName
Dim prjObject
Dim parmList
Dim parm

Dim spList
Dim sp
Dim spParamList
Dim spParam
Dim spParamName
Dim spParamValue

Dim n
Dim i
Dim t
Dim id

id=Array("111111111","22222222","33333333")


'-----------------------------------

' The name and location of the project file that will be opened and run by this script.
prjName = "C:\SAS\EG\Samples\XXXXX.egp" 'Project Name

for t = 0 to UBound(id)

' Start the app and open the project 
Set app = CreateObject("SASEGObjectModel.Application.8.1")

Set prjObject = app.Open(prjName,"")

'---------------------------------
'Begin processing the project
'---------------------------------

' Discover the parameters for the project
Set parmList = prjObject.Parameters
Wscript.Echo "Project has " & parmList.Count & " parameters."

' Get the default value from the first parameter
Set parm = parmList.Item(0)
WScript.Echo parm.Name & " parameter has default value of " & parm.DefaultValue

' Change the value of the parameter to 'M' and display the new value.
parm.Value = id(t)

WScript.Echo parm.Name & " parameter has been set to value of " & parm.Value

'-------------------------------
'Begin processing the stored process
'-------------------------------
Set spList = prjObject.StoredProcessCollection

' Get the number of parameters for the store process
Wscript.Echo "StoredProcess has " & spList.Count & " parameters."

' Cycle through the list of stored processes and the parameters for each of them.
for n=0 to (spList.Count - 1)
    Set sp = spList.Item(n)
    ' Get the list of parameters
    Set spParamList = sp.Parameters

    ' Process each stored process parameter
      for i=0 to (spParamList.Count - 1)
    
        Set spParam = spParamList.Item(i)
        ' Get the name and default value for the parameter          
        spParamName = spParam.Name
        spParamValue = spParam.DefaultValue

        ' Display the parameter information to the user
        WScript.Echo spParamName & " parameter has default value of " & spParamValue
        ' Change the value of the parameter
        spParam.Value = id(t)
        ' Display the modified value
        WScript.Echo spParamName & " parameter has been set to value of " & spParam.Value
    
        ' Save the project with the updated stored process
        prjObject.Save
    Next
Next

' Run the new project
prjObject.Run

' Make sure the project is saved after it has been run.
prjObject.Save
    
' Close the project and application.
prjObject.Close

Next
app.Quit
1 ACCEPTED SOLUTION

Accepted Solutions
luizcbarrosaf
Fluorite | Level 6

I got it, the final code is below.

 

Option Explicit

'--------------
Dim app
Dim prjName
Dim prjObject
Dim parmList
Dim parm


Dim n
Dim i
Dim t
Dim id

id=Array("111111111","22222222","33333333")


'-----------------------------------

' The name and location of the project file that will be opened and run by this script.
prjName = "C:\SAS\EG\Samples\XXXXX.egp" 'Project Name



' Start the app and open the project 
Set app = CreateObject("SASEGObjectModel.Application.8.1")

Set prjObject = app.Open(prjName,"")

'---------------------------------
'Begin processing the project
'---------------------------------
for t = 0 to UBound(id)

' Discover the parameters for the project
Set parmList = prjObject.Parameters
Wscript.Echo "Project has " & parmList.Count & " parameters."

' Get the default value from the first parameter
Set parm = parmList.Item(0)
WScript.Echo parm.Name & " parameter has default value of " & parm.DefaultValue

' Change the value of the parameter and display the new value.
parm.Value = id(t)

WScript.Echo parm.Name & " parameter has been set to value of " & parm.Value



' Run the new project
prjObject.Run
WScript.Sleep 5000
Next

' Make sure the project is saved after it has been run.
prjObject.Save
    
' Close the project and application.
prjObject.Close


app.Quit

View solution in original post

3 REPLIES 3
jimbarbour
Meteorite | Level 14
Personally, I would write some intermediate SAS code to repeatedly execute the main SAS code you're setting this up for. Have the VB Script trigger the intermediate SAS code and let the intermediate SAS code handle the parameters and the repeated execution of the main SAS code.

Jim
AlanC
Barite | Level 11

When does t get updated? Did I miss it?

 

Also, you would be FAR better off using C# to do this vs VBScript. All of the code I post that shows using the SAS object model is in C# and Chris H posts a lot of his stuff using C# as well. 

 

If t is not the issue, I would and pull out enough info from the C# examples and do this. I have not played with the parameters in the SPs but you should be able to pull it. Another thought I would have is if you are closing the objects completely before you iterate again. I am not sure why there is this open/save/open/save loop. You should be able to do this all in 1 pass. 

https://github.com/savian-net
luizcbarrosaf
Fluorite | Level 6

I got it, the final code is below.

 

Option Explicit

'--------------
Dim app
Dim prjName
Dim prjObject
Dim parmList
Dim parm


Dim n
Dim i
Dim t
Dim id

id=Array("111111111","22222222","33333333")


'-----------------------------------

' The name and location of the project file that will be opened and run by this script.
prjName = "C:\SAS\EG\Samples\XXXXX.egp" 'Project Name



' Start the app and open the project 
Set app = CreateObject("SASEGObjectModel.Application.8.1")

Set prjObject = app.Open(prjName,"")

'---------------------------------
'Begin processing the project
'---------------------------------
for t = 0 to UBound(id)

' Discover the parameters for the project
Set parmList = prjObject.Parameters
Wscript.Echo "Project has " & parmList.Count & " parameters."

' Get the default value from the first parameter
Set parm = parmList.Item(0)
WScript.Echo parm.Name & " parameter has default value of " & parm.DefaultValue

' Change the value of the parameter and display the new value.
parm.Value = id(t)

WScript.Echo parm.Name & " parameter has been set to value of " & parm.Value



' Run the new project
prjObject.Run
WScript.Sleep 5000
Next

' Make sure the project is saved after it has been run.
prjObject.Save
    
' Close the project and application.
prjObject.Close


app.Quit

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2371 views
  • 2 likes
  • 3 in conversation