To keep track of the tasks I run during the night, I am trying to find what could be the best way to export the log files for each of my daily projects (each of them containing several SAS Program). I found out about the SAS Project Log recently, which basically summarize the logs from all the programs within a SAS Project.
I discovered @CaseySmith's answer on the SAS Community forum, basically tweaking the .vbs script to save the SAS Project log file to a .txt using the following code:
Set objProjectLog = objProject.ProjectLog objProjectLog.Clear() objProjectLog.Enabled = True strProjectLog = objProjectLog.Text objProjectLog.SaveAs "c:\temp\projectLog.txt"
But I don't know where to add it in my current .vbs script:
Option Explicit
Dim app
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
Dim prjObject
prjName = "C:\Users\kermit\Desktop\Project.egp" 'Project Name
Set app = CreateObject("SASEGObjectModel.Application.8.1")
If Checkerror("CreateObject") = True Then
Exit Sub
End If
'-----
' 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 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
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
Can someone tell me how to output the entire SAS Project Log File to an external .log file? And if possible replacing it, not appending it to the past one.
Thanks
In each sas program you can use the proc printto procedure to output to a unique text file log.
Alternately, you can create a new sas program and preface it with a proc printto procedure and have it run all of your unique sas jobs using %include. Like so:
proc printto new log="C:\filepath\log.txt";
run;
%include "C:\filepath\job1.sas";
%include "C:\filepath\job2.sas";
/* repeat as necessary */
%include "C:\filepath\jobn.sas";
All the logs from the jobs ran using this sas job will be compiled into your c:\filepath\log.txt file.
Of course, that's assuming you are able to avoid using vba in running any of your programs.
The new option in the proc printto statement will replace instead of append to the file.
If you need a new log every time, you can have sas generate the txt file with a date.
proc printto log = "c:\filepath\log_%sysfunc(today,yymmddn6.).txt";
run;
In each sas program you can use the proc printto procedure to output to a unique text file log.
Alternately, you can create a new sas program and preface it with a proc printto procedure and have it run all of your unique sas jobs using %include. Like so:
proc printto new log="C:\filepath\log.txt";
run;
%include "C:\filepath\job1.sas";
%include "C:\filepath\job2.sas";
/* repeat as necessary */
%include "C:\filepath\jobn.sas";
All the logs from the jobs ran using this sas job will be compiled into your c:\filepath\log.txt file.
Of course, that's assuming you are able to avoid using vba in running any of your programs.
The new option in the proc printto statement will replace instead of append to the file.
If you need a new log every time, you can have sas generate the txt file with a date.
proc printto log = "c:\filepath\log_%sysfunc(today,yymmddn6.).txt";
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.