BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
js5
Pyrite | Level 9 js5
Pyrite | Level 9

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.Quit

One 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.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

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.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

View solution in original post

2 REPLIES 2
sbxkoenk
SAS Super FREQ

Let's ask the author of that SAS Communities Library article.
Calling @ChrisHemedinger .

 

BR, Koen

ChrisHemedinger
Community Manager

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.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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