2

I use SAS EG, and am trying to schedule some daily work.

  1. is there a way to schedule a order list instead of scheduling the whole process flow?
  2. if not, I looking for a code that can execute order list, so that I can only schedule on that program...
Joe
  • 62,789
  • 6
  • 49
  • 67
Zhefu Chen
  • 21
  • 2

2 Answers2

1

http://support.sas.com/kb/19/020.html

By design, the option to Schedule an Ordered List is not enabled. To circumvent the problem, select and copy the objects from the project and paste them into a new Process Flow. Then arrange them in the order you wish and, finally, schedule the Process Flow.

For details on all the ways you can schedule jobs in EG, these two papers have excellent details. : http://blogs.sas.com/content/sasdummy/2012/04/17/doing-more-with-sas-enterprise-guide-automation/ http://support.sas.com/documentation/onlinedoc/guide/examples/SASGF2012/Hemedinger_298-2012.pdf

Keneni
  • 705
  • 5
  • 12
0

If you're willing to do a bit of scripting, either in VBScript or Powershell or .Net, this is possible. It's not recommended, though, because as Keni notes, SAS explicitly didn't make this possible, and says so (as opposed to just forgetting to do it). So I am not sure why that is - and so it's possible this could lead to problems.

However: it is possible. The hooks in the API exist to run an ordered list, at least from a technical standpoint. Again - I don't know if this risks conflicts or anything else, and you might want to consider posting in the SAS Community forum to see if Chris H or one of the other folks on that forum can clue you in as to why it's not made possible in the IDE.

Basically, you can access the Ordered List through the API via the ContainerCollection that is part of the project. Inside that container collection is a container called "Ordered Lists". Inside that container is a container for each ordered list in the project. So, you might access that through project.ContainerCollection.Item(i).Items.Item(j), where i seems to be 0 consistently in my initial testing (but don't rely on that, I'm not sure if it's always 0) and j is the number of the particular ordered list you're running.

To do this, I created a copy of the VBScript that EGuide produces when you ask it to schedule a process flow, and tweaked it to find the ordered list. This is very kludgy - in part because my VBScript knowledge is mediocre and old, and in part out of a desire to get this done faster. You may have to make changes to make this work (other than adjusting the path to project and project file name in the prjName variable and the containerName variable (which should be your Ordered Lists's name).

What it does is cycles through all Containers in the ContainerCollection, and tests if they're named "Ordered Lists". Then it cycles through the containers in that container, and tests if they're named whatever you put in the containerName variable (your Ordered List's name). When it finds one that is, it exits the for loop and runs that container (i.e., runs that ordered list).

This can then be scheduled, or run directly (either by double clicking in Windows, or using cscript.exe in console). If you're running EG in a non-Windows environment, it's possible this still could work (if you have a VBScript compiler), but I'm not sure if the API works the same way or not. (Your SAS environment shouldn't matter, just the EG environment.)

Option Explicit
Dim app         ' As SASEGuide.Application

Call dowork

'shut down the app
If not (app Is Nothing) Then
    app.Quit
    Set app = Nothing
End If


Sub dowork()
    On Error Resume Next
    '----
    ' Start up Enterprise Guide using the project name
    '----
    Dim prjName     ' As String
    Dim prjObject   ' As SASEGuide.Project
    Dim containerName     ' As String
    Dim containerObject   ' As SASEGuide.Container
    Dim containerColl     ' As SASEGuide.ContainerCollection
    dim orderedListObject ' as SASEguide.Container

    prjName = "\\pathtoproject\test project.egp" ' Project Name
    containerName = "My Ordered List" ' Name of the Ordered List

    Set app = CreateObject("SASEGObjectModel.Application.7.1")
    If Checkerror("CreateObject") = True Then
        Exit Sub
    End If

    Set prjObject = app.Open(prjName,"")
    If Checkerror("App.Open") = True Then
        Exit Sub
    End If


    '-----
    'Get The Container Collection and Object
    '-----    
    Set containerColl = prjObject.ContainerCollection
    If Checkerror("Project.ContainerCollection") = True Then
        Exit Sub
    End If

    Dim i        ' As Long
    Dim j        ' As Long
    Dim count    ' As Long
    Dim count_OL ' as Long
    count = containerColl.count
    For i = 0 To count - 1
        Set containerObject = containerColl.Item(i)

        If Checkerror("ContainerCollection.Item") = True Then
            Exit Sub
        End If

        If (containerObject.Name = "Ordered Lists") Then
            count_OL = containerObject.items.count
            For j = 0 to count_OL - 1
                If Checkerror("ContainerCollection.Item") = True Then
                    Exit Sub
                End If
                Set orderedListObject = containerObject.items.item(j)
                If (orderedListObject.name = containerName) then                
                    exit for
                Else
                    Set orderedListObject = Nothing
                end if                          
            Next
            Exit For
        Else
            Set containerObject = Nothing
            Set orderedListObject = Nothing
        End If
    Next 

    If not (orderedListObject is nothing) Then
        '----
        ' Run the Container
        '----
        orderedListObject.Run
        If Checkerror("Container.Run") = True Then
            Exit Sub
        End If               
    Else
        wscript.echo "Not Found"


    End If

    '-----
    ' Save the new project
    '-----
    prjObject.Save
    If Checkerror("Project.Save") = True Then
        Exit Sub
    End If

    '-----
    ' Close the project
    '-----
    prjObject.Close
    If Checkerror("Project.Close") = True Then
        Exit Sub
    End If

End Sub

Function Checkerror(fnName)
    Checkerror = False

    Dim strmsg      ' As String
    Dim errNum      ' As Long

    If Err.Number <> 0 Then
        strmsg = "Error #" & Hex(Err.Number) & vbCrLf & "In Function " & fnName & vbCrLf & Err.Description
        MsgBox strmsg  'Uncomment this line if you want to be notified via MessageBox of Errors in the script.
        Checkerror = True
    End If

End Function
Joe
  • 62,789
  • 6
  • 49
  • 67