Hello,
I managed to automate our SAS EG runs by following the guide here: https://communities.sas.com/t5/SAS-Communities-Library/Doing-More-with-SAS-Enterprise-Guide-Automati...
Here is the code I used:
' ------------------------------------------------
' ExtractCodeAndLog.vbs
' Uses SAS Enterprise Guide automation to read an EGP file
' and export all SAS programs and logs to subfolders
' There is a new subfolder created for each process flow
' within the project
'
' This script uses the Code.Text method, which will NOT include
' other "wrapper" code around each program that
' SAS Enterprise Guide might have inserted
'
' USAGE:
' cscript.exe ExtractCodeAndLog.vbs <path-to-EGP-file>
' EXAMPLE:
' cscript.exe ExtractCodeAndLog.vbs c:\projects\DonorsChoose.egp
'
' NOTE: use proper version of CSCRIPT.exe for your SAS Enterprise Guide
' version. For 32-bit EG on 64-bit Windows, use
' c:\Windows\SysWOW64\cscript.exe
' ------------------------------------------------
' force declaration of variables in VB Script
Option Explicit
Dim Application
Dim Project
' Change if running a different version of EG
Dim egVersion
egVersion = "SASEGObjectModel.Application.8.1"
' Simple error check - looking for a project file
If WScript.Arguments.Count = 0 Then
WScript.Echo "ERROR: Expecting the full path name of a project file"
WScript.Quit -1
End If
' Create a new SAS Enterprise Guide automation session
On Error Resume Next
Set Application = WScript.CreateObject(egVersion)
WScript.Echo "Opening project: " & WScript.Arguments.Item(0)
' Open the EGP file with the Application
Set Project = Application.Open(WScript.Arguments.Item(0),"")
If Err.Number <> 0 Then
WScript.Echo "ERROR: Unable to open " _
& WScript.Arguments.Item(0) & " as a project file"
WScript.Quit -1
End If
'WScript.Echo " " & Project.Name & ", Project Flow"
'Project.Run
Dim flow
' Navigate the process flows in the Project object
For Each flow In Project.ContainerCollection
' ProcessFlow is ContainerType of 0
If flow.ContainerType = 0 and flow.name = "autoexec" Then
WScript.Echo " " & flow.Name & ", Process Flow"
flow.Run
End If
Next
For Each flow In Project.ContainerCollection
' ProcessFlow is ContainerType of 0
If flow.ContainerType = 0 and flow.name <> "autoexec" Then
WScript.Echo " " & flow.Name & ", Process Flow"
flow.Run
End If
Next
' Close the project
Project.Close
' Quit/close the Application object
Application.QuitOne issue I have discovered is that the script gives no feedback as to whether the process flow ran successfully, or whether there were any errors or warnings. Is it possible to add this without running each program separately and trying to parse its log? Thank you.
Hi @js5 ,
There isn't a "return code" or other property to check. What I recommend doing is create a program task that runs at the end of the flow that checks for success (data created/exists, etc.) and then use the script to examine just that one log.
Hi @js5 ,
There isn't a "return code" or other property to check. What I recommend doing is create a program task that runs at the end of the flow that checks for success (data created/exists, etc.) and then use the script to examine just that one log.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.