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

Hello,

 

I would like to print the log to file.
In log I should have everything above the command (proc printto log is not a solution).

I read I can print log to file by using DM statement.

Why below code does not work?

 

%let path = ...;
%let fin=&path.\test.log;

data test;
a="test";
run;

dm log "file '&fin.' replace";

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

With SAS EG, the SAS session you are working with is more like batch SAS, so you have to use code that is compatible with batch mode. PROC PRINTO will work but DM statements wont.

 

If I want log files, I find it easier just to run the complete program as a batch job which produces a log file automatically, no coding required. That way your EG and batch job code can be exactly the same. Running in EG, the log goes to the log panel, in batch it is written to the log file. Batch jobs in SAS 9.4 can be run from the SAS Management Console tool as it isn't available in EG.

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26
proc printto log="whateverfilename.log"; run;
data test;
a="test";
run;
proc printto; run;
--
Paige Miller
starosto
Fluorite | Level 6

@PaigeMiller thank you for your reply.
However, as I mentioned previously printto procedure is not a solution for me.
The code I am writing will be included in other codes and I do not have any guarantee that author include proc printto at the vey beginning of sas program.

 

 I am looking for a solution with dm statement. 

 

 

PaigeMiller
Diamond | Level 26

Well, I don't know why you can't use PROC PRINTTO, you seem to have decided that the exact tool in SAS that allows you to save the log in a file is not an acceptable solution. Of course, you are free to make such a decision, but could you at least explain why you can't use PROC PRINTTO?

--
Paige Miller
Ksharp
Super User

I have no problem.

%let path = c:\temp ;
%let fin=&path.\test.log;

data test;
a="test";
run;

dm log "file '&fin.' replace";

 

Ksharp_0-1681474726597.png

 

starosto
Fluorite | Level 6
I am running this code in Windows SAS EG and it does not work...
Quentin
Super User

You're running this code on Windows SAS in Display Manager, right?  (So not Enterprise Guide or Studio, and not a batch job)

 

Your code worked for me as is.  I think it's better to wrap the entire DM string in quotes, and have semicolons to end the log command and the file command.  So I tend to code this like:

 

dm "log; file ""&fin"" replace;" ;

The single quotes you're using around &fin work fine, I'm just in the habit of avoiding single quotes in the macro language unless I'm using them to prevent resolution.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
starosto
Fluorite | Level 6
I am running this code in Windows SAS EG and it does not work...
I tried with your adjustments, and it does not work...
Tom
Super User Tom
Super User

@starosto wrote:
I am running this code in Windows SAS EG and it does not work...
I tried with your adjustments, and it does not work...

The DM statement will never work in SAS code run from Enterprise Guide because the SAS session that Enterprise Guide connects to so that it can submit and run SAS code is not running Display Manager.  So you cannot use Display Manager commands.

Quentin
Super User

The DM command will not work in EG.  It's a Display Manager command.  I don't know if EG has a way to use SAS code to save the log to a file.  You might want to ask that question in EG community.  

 

One workaround might be to use PROC PRINTTO as Paige mentioned.  EG does let you add custom pre-code and post-code to every submission.  So as a hack, you could add as pre-code:

proc printto log='...' new;
run;

And as postcode:

proc printto log=log;
run;
data _null_;
  input '...' ;
  put _infile_;
run;

I really wish SAS would make it possible to execute system option ALTLOG  during a SAS session.  I think that would make it easier to capture the log as a file, without having to redirect the log.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
SASKiwi
PROC Star

With SAS EG, the SAS session you are working with is more like batch SAS, so you have to use code that is compatible with batch mode. PROC PRINTO will work but DM statements wont.

 

If I want log files, I find it easier just to run the complete program as a batch job which produces a log file automatically, no coding required. That way your EG and batch job code can be exactly the same. Running in EG, the log goes to the log panel, in batch it is written to the log file. Batch jobs in SAS 9.4 can be run from the SAS Management Console tool as it isn't available in EG.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 10 replies
  • 2492 views
  • 4 likes
  • 6 in conversation