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.

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!

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.

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!

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
  • 2 replies
  • 474 views
  • 2 likes
  • 3 in conversation