BookmarkSubscribeRSS Feed

Doing More with SAS Enterprise Guide Automation

Started ‎12-01-2017 by
Modified ‎05-09-2023 by
Views 35,202

This article contains supporting information for a SAS Global Forum 2012 paper: Not Just for Scheduling: Doing More with SAS Enterprise Guide Automation. While the paper is several years old, the techniques it describes remain the same and relevant for current versions of SAS Enterprise Guide.  I've updated the code for many of the examples so you can try them with modern versions.

Abstract

SAS Enterprise Guide supports a rich automation model that allows you to "script" almost every aspect of opening and running SAS Enterprise Guide projects. While this is most often used with the built-in "scheduler" function to simply run a project or process flow unattended, you can also write your own scripts that automate much more. You can create new projects on the fly, supply values for project prompts, run individual tasks, export results, and more. You're not limited to the traditional VBScript method of automation; you can also use more sophisticated frameworks such as Windows PowerShell or Microsoft .NET.

 

This paper describes the concepts behind automation for SAS Enterprise Guide, and provides examples to accomplish a variety of tasks using the different scripting technologies.

To watch me explain these concepts and to see a demo of building and running these scripts, watch this portion of my SAS Enterprise Guide "advanced techniques" tutorial.

 

Online Materials

 

VBScript Examples

To use each VBScript example, save the linked file to your local PC with a ".vbs" file extension. These are hosted on GitHub so you can click through and see a preview of the code. 

 

You can then run the examples on your local PC with CSCRIPT.EXE, which is part of the Windows operating system. See this blog post for special considerations regarding the 64-bit versus 32-bit versions of CSCRIPT.EXE.

 

  • NewApp.vbs - a simple "are you there" test to verify you're able to invoke SAS Enterprise Guide from a script
  • BatchProject.vbs - run a SAS program similar to a classic "batch" mode, but driving it from SAS Enterprise Guide
  • ShowProfiles.vbs - list the available SAS metadata connections that you have defined in your local installation
  • ExtractCode.vbs - export all SAS program nodes from the project you specify
  • ExtractCodeAndLog.vbs - export all code and SAS logs from the project file, storing them in a local folder for archiving

Here's an example of the first script, inline:

 

' force declaration of variables in VB Script
Option Explicit
Dim Application
' Create a new SAS Enterprise Guide automation session
' Change if running a different version of EG
Dim egVersion 
egVersion = "SASEGObjectModel.Application.7.1"

Set Application = WScript.CreateObject(egVersion)
WScript.Echo Application.Name & ", Version: " & Application.Version

Application.Quit

 

And its output:

 

C:\automation>%windir%\syswow64\cscript.exe NewApp.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

Enterprise Guide, Version: 7.100.5.0

 

All VBScript examples have been updated and tested to work with SAS Enterprise Guide v7.1. If using SAS Enterprise Guide 8.1 or later (such as 8.3), change the object model version like this:

 

Dim egVersion egVersion = "SASEGObjectModel.Application.8.1"

 

PowerShell Examples

How to run Windows PowerShell scripts - post on The SAS Dummy blog

Using Windows PowerShell to report on SAS Enterprise Guide projects

"PowerShell"-tagged posts from The SAS Dummy blog

 

To use these PowerShell examples, save the files as PS1 files on your local machine, and then run them within a PowerShell console window or by using the powershell -command option.

  • ListProfiles.ps1 - list the available SAS metadata profiles that you have defined in your local installation
  • DescribeEGProject.ps1 - create a delimited report of all of the objects within your EGP project file
  • ListProjectContents.ps1 - accepts a piped list of EGP files and creates a cumulative report of all of their contents.

All PowerShell examples have been updated and tested to work with SAS Enterprise Guide v7.1.

 

Example output from DescribeProject.ps1Example output from DescribeProject.ps1

Microsoft .NET Examples

Getting Started with Microsoft .NET - Microsoft MSDN site, includes link to download the free "Express"/Community editions of Visual C# and Visual Basic.NET

 

SAS Enterprise Guide project file "searcher": EGPSearch (GitHub site file with EXE and source code)

Note: this example was built based on SAS Enterprise Guide 4.3 -- it won't run with later versions without modifications and rebuilding it.

 

This is a sophisticated example that shows how you can use automation and Microsoft .NET to create a tremendous productivity tool for managing your SAS Enterprise Guide projects. This tool allows you to search within a collection of EGP files to find any text within SAS programs, logs, notes, and generated code from tasks and queries.

 

600px-Egpsearch_screenshot.png

 

A non-automation version of the EGP Searcher application is available here.

Version history
Last update:
‎05-09-2023 04:34 PM
Updated by:
Contributors

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags