SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
KermitTheFrog
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
JNR
Calcite | Level 5 JNR
Calcite | Level 5

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;

 

View solution in original post

1 REPLY 1
JNR
Calcite | Level 5 JNR
Calcite | Level 5

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;

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 7259 views
  • 1 like
  • 2 in conversation