プロジェクトの自動化

バッチモードでのプロジェクトの実行

SAS Enterprise Guideアプリケーションの外部からSAS Enterprise Guideプロジェクトをバッチモードで実行するには、プロジェクトを保存してから、スクリプトプログラムを使ってプロジェクトを実行します。

  1. SAS Enterprise Guideプロジェクトを設定します。SAS Enterprise Guideでプロジェクトを作成し、データを追加してから、そのデータに対して実行するタスクを実行します。必ず、タスクを実行し、プロジェクトに保存してください。プロジェクトを保存します。
  2. プロジェクトを実行して指定した場所に出力を保存するスクリプトファイルを作成するか、サンプルのVBScriptプログラムを使用します。
  3. Windowsエクスプローラでスクリプトファイルをダブルクリックしてスクリプトを実行します。結果を表示するには、SAS Enterprise Guideでプロジェクトを開きます。

トラブルシューティングのヒントは次のとおりです。

プロジェクトが実行されない。

DCOMサーバーは、バッチモードでのプロジェクトの実行には使用できません。

Windowsエクスプローラで、スクリプトプログラムが開けない。

WSHがインストールされているか確認してください。

プログラムが短時間で実行され、出力プロジェクトファイルが作成されていない。

出力ディレクトリが存在するか確認してください。

プログラムの実行時に、スクリプト実行エラーが発生した。

プロジェクトがSAS Enterprise Guideでまだ開いていないこと、およびプロジェクト名を正しく入力したことを確認してください。

このVBScriptプログラムは、保存したSAS Enterprise Guideプロジェクトの保存先と名前の入力を要求し、C:\Program Files\SASHome\SASEnterpriseGuide\release-number\Sample\ディレクトリに結果を保存します。このプログラムでは、プロジェクトのすべてのタスクが実行されます。プロジェクトから選択したタスクを実行するには、プロセスフローを使用するサンプルプログラムを利用してください。

' **************************************************************************
' This sample uses the SAS Enterprise Guide automation object model to 
' open an example project, run the entire project, and save the project file 
' as a new file. The script also saves a copy of all data and task results in
' the folder you specify in that SaveAs statement. The sample also creates
' a .txt file that lists the data sets, tasks, and results objects in the 
' project.
'
' The goal of this example is to illustrate how to run and save objects
' in a project by using automation.
'
' To run the automation script, copy this example to a text file and save  
' it as Sample_RunSave.vbs in C:\Program Files\SASHome\SASEnterpriseGuide\
' release-number\Sample. 
' If you prefer, you can change the project path statements to point to a 
' different folder.
'
' Create a SAS Enterprise Guide project called Sample_RunSave.egp that has 
' at least one task that creates at least one result and save it in the same
' path as the script. The name of the project file and the path to that file
' must match the project name and the path that is specified in the script. 
' **************************************************************************

Dim app 		'Represents the SAS Enterprise Guide Application object
Call dowork	'Call the subroutine to perform the work and run the task

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

'************************************************************************
' The subroutine dowork is where the task is run and the output is produced.
' The output is saved to a file that is represented in the variable "outfile". One
' output file is saved for each results format that is produced by the task.
'***********************************************************************

Sub dowork()
	On Error Resume Next
	'----
	'Start Enterprise Guide using the project name
	
Dim prjName 	'Represents the name of the project being run
Dim prjObject	'The actual project object that is running
Dim dc  		'Represents the DataCollection in the project
Dim d   		'index for DataCollection
Dim tc  		'Represents the TaskCollection under each data object
Dim t   		'index for TaskCollection
Dim rc  		'Represents ResultsCollection under each Task
Dim r   		'index for ResultsCollection
Dim outfile	'Used to define a path for the Contents file
Dim fileSys	'Represents the FileSystemObject that lets you write files
Dim Contents	'Represents the File you are going to write
Dim ext		'Used to store extension of results


outfile = "C:\Program Files\SASHome\SASEnterpriseGuide\8.1\Sample\
   SampleRunSave_ProjectContents.txt"  'Output file name

    Set fileSys = CreateObject("Scripting.FileSystemObject")
    Set Contents = fileSys.OpenTextFile(outfile, 2, True)

    'Name the project to run
    prjName = "C:\Program Files\SASHome\SASEnterpriseGuide\8.1\Sample\Sample_RunSave.egp"
      'Project Name
      
    Set app = CreateObject("SASEGObjectModel.Application.8.1")
    If Checkerror("CreateObject") = True Then
        Exit Sub
    End If
    
    'Open the Enterprise Guide application and the project
    '-----
    ' open the project
    '-----
    Set prjObject = app.Open(prjName,"")
    If Checkerror("app.Open") = True Then
        Exit Sub
    End If
    
        
    '-----
    ' run the project
    '-----
    prjObject.run
    If Checkerror("Project.run") = True Then
        Exit Sub
    End If
    
    '-----
    ' Save all the results from all of the tasks under all of the data sets
    '-----
    d=0
    Set dc = prjObject.DataCollection
    Do While d < dc.Count
	Contents.WriteLine("DataSet Name: " & dc(d).Name)
      t=0
      Set tc = dc(d).Tasks
      Do While t < tc.Count
        Contents.WriteLine("     TaskName:  " & tc(c).Name)
        r=0
        Set rc = tc(t).Results
        Do While r < rc.Count
           ext = ".txt"          'default extension for output file
           Contents.WriteLine("        Results Name:  " & rc(r).Name)
           if Left(rc(r).Name,3) = "HTM" then ext = ".html"
           if Left(rc(r).Name,3) = "RTF" then ext = ".rtf"
           if Left(rc(r).Name,3) = "PDF" then ext = ".pdf"
           rc(r).SaveAs("C:\Program Files\SASHome\SASEnterpriseGuide\
              release-number\Sample\Sample_RunSave_" & d & t & ext)
           r = r + 1
        Loop
      t = t + 1
      Loop
   d = d + 1
   Loop

           
    '-----
    ' 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

'***********************************************
' This function is an error handler.
'***********************************************
Function Checkerror(fnName)
    Checkerror = False
    
    Dim strmsg
    Dim errNum
    
    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

プロジェクトとプロセスフローのスケジューリング

SAS Enterprise Guideでは、Microsoft Windowsタスクスケジューラを使用して、指定時間かまたはシステムイベントの結果として実行されるようにプロジェクトとプロセスフローをスケジュールできます。デフォルトでは、タスクスケジューラを開くと、SAS Enterprise Guideでスクリプトが自動作成されて、プロジェクトまたはプロセスフローが実行されます。プロジェクトまたはプロセスフローをスケジュールすると、スクリプトとタスクをいつ実行するかを指定する条件を含むスケジュール済みタスクがタスクスケジューラにより作成されます。スケジュール済みタスクはプロジェクトペインに追加されます。

注: プロジェクトをローカルコンピュータに保存してから、スケジュール済みタスクを作成する必要があります。

プロジェクトまたはプロセスフローをスケジュールするには

  1. プロジェクトをスケジュールするには、詳細オプション を選択し、プロジェクトのスケジュールを選択します。

    プロセスフローをスケジュールするには、プロセスフローを開いて次のどちらかの方法を実行します。

    • プロジェクトペインのプロセスフローの名前を右クリックして、スケジュールを選択します。
    • プロセスフローツールバーで、スケジュールをクリックします。

    Microsoft Windowsタスクスケジューラとのインターフェイスが開きます。

  2. 一般タブの名前ボックスに新しい名前を入力すると、スケジュール済みタスクのデフォルト名を変更できます。タスク名は重複しないようにしてください。また、一般タブでは他のプロパティも入力または変更できます。デフォルトでは、スケジュール済みタスクは、タスクをスケジュールしたユーザーのアカウントを使用して実行されます。
  3. トリガタブでは、スケジュール済みタスクを開始するために使用されるトリガまたは基準を指定できます。トリガは時間基準かイベント基準にできます。たとえば、時間基準トリガでは、特定の時間か、または定期的に繰り返すスケジュールでタスクを開始できます。イベント基準のトリガでは、ユーザーがログオンするときや、コンピュータがアイドル状態に入ったときなどに、システムイベントの結果としてタスクが開始されます。デフォルトでは、タスクは、現在の時刻に毎日実行するようにスケジュールされます。タスクのトリガが2つ以上ある場合、そのトリガのいずれかが発生するとタスクが開始されます。
  4. 操作タブでは、タスクの実行時に実行する操作を1つ以上指定できます。デフォルトでは、スケジュール済みタスクによってプロジェクトまたはプロセスフローが実行されます。デフォルトの操作はプログラムの開始で、デフォルトのプログラムまたはスクリプトは生成されたスクリプトファイルです。異なるスクリプトを実行するには、スクリプトを選択して編集をクリックします。別のアクションを追加するには、新規作成をクリックします。
  5. 条件タブでは、タスクを実行するかどうかを制御する条件を指定できます。条件は、タスクの開始がトリガされた後で評価されます。
  6. 設定タブでは、タスクの実行、停止または削除のオプションを指定できます。
  7. 実行時間タブでは、タスクの実行がスケジュールされている時間のリストを表示できます。履歴タブでは、タスクが実行された時間のリストを表示できます。
  8. スケジュール済みタスクを保存するには、OKをクリックします。スケジュール済みタスクと関連するスクリプトがプロジェクトペインに追加されます。

スケジュール済みプロジェクトまたはプロセスフローを実行するには、スケジュール済みタスクの結果を保存できるようにプロジェクトを閉じます。プロセスフローのタスクをスケジュールした場合、このプロセスフローを含むプロジェクトを閉じます。

スケジュール済みタスクを編集するには、プロジェクトペインでスケジュール済みタスクを右クリックして開くを選択します。タスクスケジューラでスケジュール済みタスクが開きます。

最終更新: 2024年8月21日