Using this code, when I loop through objects in a process flow, I find that certain objects, specifically tasks, are skipped. In this recent instance (I have not provided the EGP file) the code below opened and recognized all the other objects and created a message box output ("Unsorted<--"...) relaying their name, but not so for the "Summary Tables" task. Another version of the code outputs the code of program nodes and query builder objects, successfully; I would also like to access code connected to tasks as well.
Because I'm not getting a "item.Name" or an "item.Type" from the task, does that mean the task is not in the process flow container?
And its hard to search for this type of question, forgive me if its repeated.
Code is run using Excel VBA; Code is based on @ChrisHemedinger 's code, published here:
Option Explicit
Dim Application ' As SASEGuide.Application
Sub EGPConvert_v8()
Dim Project
' Change if running a different version of EG
Dim egVersion
egVersion = "SASEGObjectModel.Application.8.1"
Dim item
Dim flow
Dim Unsorted
Dim Items_Sorted
Dim outputFilename As String
Dim i As Integer
Dim EGPfile As String
Dim programsFolder As String
Dim objFS 'As "Scripting.FileSystemObject"
Dim objOutFile ' As TextStream
'********************************************************
' Get...
EGPfile = Interface.Get_FileName() 'File name and path
programsFolder = Interface.Get_Destination() 'Folder path
'********************************************************
' Create a new SAS Enterprise Guide automation session
On Error Resume Next
Set Application = CreateObject(egVersion)
If Err.Number <> 0 Then
MsgBox "ERROR: Need help with 'Set Application = CreateObject(egVersion)"
End
End If
MsgBox Application.Name & ", Version: " & Application.Version & vbCrLf & "Opening project: " & EGPfile
'********************************************************
' Open the EGP file with the Application
Set Project = Application.Open(EGPfile, "")
If Err.Number <> 0 Then
MsgBox "ERROR: Unable to open " & EGPfile & " as a project file"
End
End If
'********************************************************
'Open the output file
MkDir programsFolder & Project.Name
outputFilename = programsFolder & Project.Name & "\" & Project.Name & ".sas"
'MsgBox "saving code to " & vbCrLf & outputFilename
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objOutFile = objFS.CreateTextFile(outputFilename, True)
'********************************************************
'Prepare the unsorted list
Set Unsorted = CreateObject("System.Collections.ArrayList")
'********************************************************
' Navigate the process flows in the Project object
For Each flow In Project.ContainerCollection
' ProcessFlow is ContainerType of 0
If flow.ContainerType = 0 Then
'MsgBox "Process Flow: " & flow.Name
' Navigate the items in each process flow
For Each item In flow.Items
MsgBox "=Unsorted<--" & item.Name & " Type: " & item.Type
Unsorted.Add item
Next
End If
Next
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.