BookmarkSubscribeRSS Feed
elwayfan446
Barite | Level 11

Good morning everyone.

 

I am curious if anyone has found a way to use code in EG to auto purge the project log when it is nearing the size limit.  It would be nice to do this rather than it failing on a scheduled job and having to go in and clear the log manually before rerunning the process flow.  Not sure it can be done but worth a shot to ask and see if anyone is doing it somehow.

18 REPLIES 18
Damo
SAS Employee

Hi @elwayfan446

 

I don't think what you're looking for exists.

You can either use Chris' solution here or turn it off using the View => Project Log menu.

 

Hope that helps (but I know this isn't the answer you wanted Smiley Wink ).

 

Cheers,
Damo

 

elwayfan446
Barite | Level 11

Thanks @Damo.  I normally use the same solution that Chris does because I use the information in the log so I don't want to turn it completely off.  I was pretty sure it couldn't be automated but wanted to see if someone figured out a way before I completely wrote it off.

 

 

CaseySmith
SAS Employee

Hi @elwayfan446,

 

Actually, there is a way...  starting in EG 7.15, you can perform Project Log operations (enable/disable, get the log text, save to file, send email, or clear) via the EG automation interface. Here is an example of the Project Log related calls you could make in a VBScript (or PowerShell script, but different syntax):

 

	Set objProjectLog = objProject.ProjectLog
	objProjectLog.Clear()

	' Other optional operations
	'objProjectLog.Enabled = True
	'strProjectLog = objProjectLog.Text
	'objProjectLog.SaveAs "c:\temp\projectLog.txt"
	
	'toList(0) = "me@here.com"
	'objProjectLog.SendMail "", "", toList, ccList, "my subject", "my body text"

 

A common use would be to add a Clear call to a scheduled .vbs file (and optionally save the project log out before clearing).

 

In a future release, we'd like to expose more options directly in the UI for automatically managing the size of the project log.

 

Casey


Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF

View now: on-demand content for SAS users

elwayfan446
Barite | Level 11

Thank you @CaseySmith.  This looks promising.  Can you clarify what you mean when you say "via the EG automation interface"?  I am trying to figure out how I can call the VBScript or Powershell code and it be able to work inside EG. 

 

Thanks!

CaseySmith
SAS Employee

Sure, here are example steps that show how the EG automation interface is used to run a project (on a schedule in this case):

  1. In EG, click File->New->Project to create a new project.
  2. Click File->New->Program to create a new program.
  3. Copy/paste this code into your program:

    proc print data=sashelp.class; run;

  4. Click File->Save Project to save the EG project.
  5. Click File->Schedule <projectName>.
  6. Click OK in the scheduler dialog to dismiss it with defaults. (A EGScript1.vbs file will then be created in same directory as your .egp file, and a Windows Scheduled Task will be created that runs the EGScript1.vbs file.)
  7. Look in the same directory where your EG project file (.egp) was saved and locate the new EGScript1.vbs file (VBScript).
  8. Close EG.
  9. Double-click the EGScript1.vbs file to run it, or run it from command-line. Note: If you have 32-bit EG on 64-bit Windows, you'll need to run it from command-line via "c:\windows\SysWOW64\cscript.exe <fullpath>\EGScript1.vbs".
  10. Re-open your saved .egp project in EG and confirm it ran (there is now an output node attached to the program in the process flow).
  11. Open the EGScript1.vbs file into a text editor to inspect and edit the VBScript code (ex. add commands similar to those I shared earlier for working with the Project Log).
  12. Close EG, re-run the EGScript1.vbs file again (with the desired edits), and confirm it performed the desired operations.

You can manually run the EGScript1.vbs file or schedule it to be run in Windows Task Scheduler.

 

Casey


Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF

View now: on-demand content for SAS users

elwayfan446
Barite | Level 11

Ah, ok.  I am with you on that part. I have several processes already scheduled this way.  I was interested in the code such as powershell to actually do the purge and then I was going to definitly schedule to run once a month or so.

 

Thanks for the help!

CaseySmith
SAS Employee

Here is an example of using the EG automation interface from PowerShell:

 

$projectList = @('C:\temp\deleteme\Project1.egp','C:\temp\deleteme\Project2.egp') 
foreach($project in $projectList) { 
    Write-Host "Start processing of " $project 
    $eguideApp = New-Object -ComObject SASEGObjectModel.Application.7.1 
    $egProject = $eguideApp.Open("$project","") 
    $egProject.run() 
    $egProject.save() 
    $egProject.close() 
    $eguideApp.Quit() 
    Write-Host "Ended processing of " $project 
}

Same objects and methods are available (since registered COM interfaces), just PowerShell syntax. The script above opens, runs, saves, then closes two EG projects, one after the other.

 

 

Casey


Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF

View now: on-demand content for SAS users

elwayfan446
Barite | Level 11

Thanks Casey!  This is very useful to have.  I can definitely think of some ways to use this. I have only ever done it using the built in schedule tool.

 

However, when I mentioned powershell, the need is for the code that does the actual purging, not necessarily runs the EG project.  Sorry for the confusion.

CaseySmith
SAS Employee

Happy to help. Yeah, the previous was just an example of using a PowerShell script to drive the EG automation interface. You can customize it to do whatever operations you are interested in. For example, here is a PowerShell script that clears the project log for the specified EG project and shows examples (commented out) of other project log operations you could perform:

 

$project = 'C:\temp\deleteme\Project1.egp'
$eguideApp = New-Object -ComObject SASEGObjectModel.Application.7.1 
$egProject = $eguideApp.Open("$project","") 
$projectLog = $egProject.ProjectLog

Write-Host "Clearing the project log in EG project: " $project 
# Clear the project log:
$projectLog.Clear()

# Other available project log operation examples...

# Enable/disable project log:
#$projectLog.Enabled = $true

# Get project log text:
#$strProjectLog = $projectLog.Text
#Write-Host "Project log text: " $strProjectLog

# Save project log to a file:
#$projectLog.SaveAs("c:\temp\deleteme\projectLog.txt")

# Email project log:
#$toList = @("me@here.com")
#$ccList = @()
#$projectLog.SendMail("", "", $toList, $ccList, "my subject", "my body text")

$egProject.Save() 
$egProject.Close() 
$eguideApp.Quit() 
Write-Host "Done."

 

Casey


Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF

View now: on-demand content for SAS users

elwayfan446
Barite | Level 11
Awesome, this looks great. As soon as I get the chance to get this set up, I will report back and flag this answered.
Sayli
Calcite | Level 5

Thank you Casey,

 

Hi,
I tried your example, after making the necessary edits, the Project Log has only this message "Project Log cleared at 3/6/2019 3:58:48 PM". Following is where I have placed my edits. Please Let me know where I am going wrong?

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

 

 

Set objProjectLog = prjObject.ProjectLog
objProjectLog.Clear()

' Other optional operations
objProjectLog.Enabled = True
'strProjectLog = objProjectLog.Text
objProjectLog.SaveAs "c:\temp\projectLog.txt"

toList(0) = "sayli.XXXX@XXXX.com"
objProjectLog.SendMail "", "", toList, ccList, "my subject", "my body text"

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

CaseySmith
SAS Employee

Hi @Sayli,

 

What do you wish to accomplish? (ex. clear the project log, enable the project log, get the project log text, save the project log to a file, and/or email the project log?)  The code I shared is just examples of the project log operations you can perform.  You included all of them below in your VBScript.  So, what it should do (as currently written) is...  run the project, clear the project log, turn on the project log, save the project log to the file "c:\temp\projectLog.txt", email the project log, and then save the project.

 

If it isn't behaving as you would expect, I would recommend verifying them one at a time to isolate the problem.  For example, first manually turn on the project log and run any program (ex. "%put hello;") to add at least one log to the project log.  Close and save the project, then run your VBScript with just the objProjectLog.Clear() operation (comment out the other project log operations).  Re-open the project and make sure the project log was cleared.  If that works, move on to the next project log operation and exercise it by itself.  If the first operation doesn't work, step back and make sure your VBScript runs your EG project in the first place (without any project log operations).

 

Let me know which project log operations are working for you and which are not.

 

Casey


Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF

View now: on-demand content for SAS users

Sayli
Calcite | Level 5
Thanks Casey.

I was trying to clear the old project log and then copy the new one instead of adding the new project logs. Clearing the project log every time will reduce the size of the project file. I figured out that my place of the commands was wrong. I was clearing the log after running the project hence it was clearing out data for recent run as well.

So i start the VBA script with clearing the log first and then running the project and then saving new log!
CaseySmith
SAS Employee

Great, glad you got it figured out!

 

Casey


Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF

View now: on-demand content for SAS users

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 18 replies
  • 7173 views
  • 5 likes
  • 6 in conversation