BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Qing_End
Fluorite | Level 6

Hi, All.

My working environment transfered from SAS Base to SAS EG in last week. In my working environment, we need to export LOG and analysis log and get a overall summary. In SAS Base environment, I use following statement to export log file.

DM "log;file filename;"

But in EG, the DM command is not supported.

Does anyonce know any statement or functions in EG equal to above statement?

Proc printto statement not work in my situation as the proc printto does not export log already exists .

Thank you.

 

1 ACCEPTED SOLUTION

Accepted Solutions
CaseySmith
SAS Employee

Another way you could accomplish is with EG's automation interface.  For example, add the following to the EGScript1.vbs file that gets created when you schedule an EG project:

 

    '-----
    ' export the log for each program
    '-----
    Dim code
    For Each code in prjObject.CodeCollection
        'MsgBox code.Log.Text
        code.Log.SaveAs "c:\temp\" & code.Name & ".log"
    Next

 

Here is an example of the full VBS file (I commented out the running and saving of the project.  Up to you to decide what you want the script to do.):

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\cassmi\Desktop\ExportAllLogs.egp"    'Project Name
      
    Set app = CreateObject("SASEGObjectModel.Application.7.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
    
	
    '-----
    ' export the log for each program
    '-----
    Dim code
    For Each code in prjObject.CodeCollection
        'MsgBox code.Log.Text
        code.Log.SaveAs "c:\temp\" & code.Name & ".log"
    Next
            
    '-----
    ' 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

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

View now: on-demand content for SAS users

View solution in original post

17 REPLIES 17
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, why does:

proc printto log="c:\alogfile.txt";

run;

 

Not work?  Just need to specify the filename, and put that before code you need to run, per:

http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001330273.htm

 

Qing_End
Fluorite | Level 6

The situation is that I can't just simply put the proc printto code before SAS code.

I need another way to put log which exsist before my code to external file.

Thanks.Man Embarassed

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, your process isn't clear.  You can't run code?  Do the files already exist then?  If so you would need some sort of OS scripting to copy them across.  What is the clear and concise process you are doing, indicate at what point you need to redirect the log (if indeed redirecting the log is what we are talking about).  Can't remember about EG setup, but SAS has autoexec.  You could also create a run_all program separate from what you have, e.g.:
%inc (file=);

  proc printto log="&file..txt";

  run;

  %inc "&file..sas";

  proc printto;

  run;

%mend inc;

%inc "c:\file1";

%inc "c:\file2";

Qing_End
Fluorite | Level 6
Thanks man. What I need is to redirect the log file after I run my program. but I can't add proc printto to statement before my program. The real picture is that I need to check my log after my run my program. This can be easily achieved in SAS BASE through DM command. But I don't find any sort of ways in EG.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Ok, I thnk I see.  You run a program (can't run anything else other than that), then once that is run you want to take a copy of the log.  In which case you will need to know where the default log is stored, it should be a text file somewhere (unless EG keeps it in memory).  You can also re-direct the log in the autoexec - as EG starts up, to a file you want, then you can copy paste that file as you want and it will not interfere with your other program.  

Qing_End
Fluorite | Level 6
Yeah, exactly. You gave me some hints. I think I need to find where the temporary log file is, then I can use SAS program to analysis it. Thanks man.
CaseySmith
SAS Employee

EG stores the log files temporarily on disk in the Windows %temp% directory in a path with this format:

 

%temp%\SEG<uniqueID>\<uniqueID>\result.log

 

For example:

C:\Users\cassmi\AppData\Local\Temp\SEG65492\dd40c683fece4362b2d3e17463b91689\result.log

 

You could write a script to copy them from here if redirecting the log in autoexec or via proc printto will not meet your needs.

 

Note: EG's project log is also stored in the same path format and file name, so you'd probably want your script to differentiate somehow.

 

Casey


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

View now: on-demand content for SAS users

Quentin
Super User

Just wanted to say I had this same question/problem about trying to access the log programmitally.  Like you, in interactive PC SAS, I used DM commands to save the current log to a file and then post-process it. 

 

Helpful to know that the EG log file is stored in a temp file on the PC.  But my guess is this still wouldn't work for my use case.  That is, in interactive PC SAS (and batch SAS) I can submit all together:

*data step;
*proc step;
*blah blah blah;
%logPostProcess()

And %LogPostProcess will process the log from steps submitted before it.  In EG connected to a remote SAS session, I would assume the code has to complete executing before the log file gets back to the local PC.  And as I type I realize even if the log file came back to my local PC in real time, it wouldn't matter, because my %logPostProcess executing on the remote server couldn't read it.

 

 

I have ended up using the PROC PRINTTO approach when I want to do log scanning in EG.  It's a bid of a hassle, but works okay.  You can set up pre-code and post-code to run the PROC PRINTTO before and after every EG submission (or on EG conection to server).  So you don't necessarily need to revise the main code.  My process is like:

  1. PROC PRINTTO redirects log to a file.
  2. Main code runs.
  3. PROC PRINTTO redirects log back to log window.
  4. Post process log file.
  5. Read the log file and stream in back to log window (so I can see log in EG log window).

 

That said, I'm only using EG for development work.  It was important to me to keep an approach that works for EG and Interactive PC SAS and batch jobs and stored process jobs.

 

I think this would be easier to manage if it were possible to specify ALTLOG option during a SAS session.  So you could just turn ALTLOG on and off any time you want to get a file copy of the log.  If you agree, please vote up:

https://communities.sas.com/t5/SASware-Ballot-Ideas/Allow-ALTLOG-to-be-specified-on-OPTIONS-statemen...

 

--Q.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Qing_End
Fluorite | Level 6

Hi, Quentin. Thank you.
I think we met the same issue.
I appreciated the way you provided. I think it's a good solution.
But I am a little confused "You can set up pre-code and post-code to run the PROC PRINTTO before and after every EG submission" as i'm a newbee in SAS EG.

Could you please explain how to achieve this task?

Thank you.

 

Quentin
Super User

Hi,

 

Warning: I haven't played with this approach, but I think it should work. 

 

In recent versions of EG (I'm using 6.1) if you go to tools->Options->SAS Program there are options where you can specify

  1. Submit SAS Code when server is connected
  2. Insert custom SAS code before submitted code
  3. Insert custom SAS code after submitted code

 

You can think of Submit SAS Code when server is connected as similar to an autoexec.  When EG starts, it connects to a server, and that code will run automatically.    In general, when you submit code in EG, EG adds a bunch of wrapper code to communicate with the server etc.  The insert custom SAS code before/after submitted code allows you to specify additional SAS code that should be added to that wrapper.  That code would be executed every time you submit code in EG.

 

So my thought is set Submit SAS Code when server is connected to be:

filename mylog "%sysfunc(pathname(work))/MyLog.log";

Set Insert custom SAS code before submitted code to be:

 

proc printto log=mylog new;
run;

Set Insert custom SAS code after submitted code to be:

 

proc printto log=log;
run;

data _null_;
  infile mylog;
  input;
  *log scanning etc;

  putlog _infile_;  *send contents of mylog back to log window;
run;

 

When you have a setup like that, any time you submit code from EG it would:

  1. Start a proc printto block.
  2. Execute the submitted code
  3. Close the proc printto block, scan the log, and write the log file to the log window.

 

So instead of taking the PC SAS approach of using DM commands to copy the content of log window to a file when you want to log scan, you take the opposite approach of always writing the log to a file.    I think something like that could work. 

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Qing_End
Fluorite | Level 6

Thank you so much Quentin.

The solution you provided is very creative and useful.

I think it will work and I will post this in this post once I have finished my experiment.

 

gravity2726
Calcite | Level 5

Click on the Log Tab(Next to Program) , Under Log you see the options export , Sent to ...............Click on export ---> Export as ....Then you save the file to desired destination

Qing_End
Fluorite | Level 6
Yeah, this is actually a way. But in this way I have to click this button every time, It is time-consuming.
CaseySmith
SAS Employee

Another way you could accomplish is with EG's automation interface.  For example, add the following to the EGScript1.vbs file that gets created when you schedule an EG project:

 

    '-----
    ' export the log for each program
    '-----
    Dim code
    For Each code in prjObject.CodeCollection
        'MsgBox code.Log.Text
        code.Log.SaveAs "c:\temp\" & code.Name & ".log"
    Next

 

Here is an example of the full VBS file (I commented out the running and saving of the project.  Up to you to decide what you want the script to do.):

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\cassmi\Desktop\ExportAllLogs.egp"    'Project Name
      
    Set app = CreateObject("SASEGObjectModel.Application.7.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
    
	
    '-----
    ' export the log for each program
    '-----
    Dim code
    For Each code in prjObject.CodeCollection
        'MsgBox code.Log.Text
        code.Log.SaveAs "c:\temp\" & code.Name & ".log"
    Next
            
    '-----
    ' 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

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

View now: on-demand content for SAS users

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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