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.
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
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
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.
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";
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.
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
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:
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:
--Q.
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.
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
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:
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.
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.
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
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
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 25. Read more here about why you should contribute and what is in it for you!
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.