Hello,
I have a code to output the log as a text file, but I found out no record was shown in the log window. Is there a way to do both? Thanks.
%let dira=%str(Pathway);
proc printto log="&dira.test\Citgo_test_&StartTime1..txt" new;
run;
@ybz12003 wrote:
Hello,
I have a code to output the log as a text file, but I found out no record was shown in the log window. Is there a way to do both? Thanks.
%let dira=%str(Pathway); proc printto log="&dira.test\Citgo_test_&StartTime1..txt" new; run;
LOG "window"? Are you running interactively?
If you were running "batch" (that is not interactively but by running SAS from the command line) then you could use the -altlog option to have a separate log file that included everything, including the part redirected by PROC PRINTTO.
Otherwise put a copy back into the normal LOG yourself by adding this step afterwards.
...
proc printto log=log; run;
data _null_;
infile "&dira.test\Citgo_test_&StartTime1..txt";
input;
put _infile_;
run;
See docs for altlog:
Basically, altlog allows you to write the log to two different locations at the same time, unlike PROC PRINTTO which changes where the log is written. Unfortunately, altlog has to be specified at SAS invocation / in a config file, you can't set it with an option during a session. But it should allow you to see the normal log in your IDE, and have the log written to a file in the background.
@ybz12003 wrote:
What is the altlog option? If using the code to put copy back in the end, I won't see anything until completing running a batch. Is there a way to monitor the log at the same time?
As Tom and Yabwon have showed, you can use PROC PRINTTO to send the log to a file, and then at the end of your code you can read that file to send the text back to your log window. That is how I do stuff like this when I'm using Enterprise Guide.
If you're using PC SAS (Display manager) in an interactive SAS session, another option is to let your log be written to the default log window, and then you can save the contents of the log file to a text file. And you can do it with code, using a DM statement with the FILE command to write the log window contents to a file:
dm "log; file ""Q:\junk\__mylog.log"" replace;";
But if you want the log messages to be written to your log window and a file at the same time, I think altlog is your best solution. I've actually never used altlog for that purpose, because I'm happy waiting for the submission to be complete before I can see the log.
I did submit a SAS ballot question years ago to recommend that SAS make it possible to turn on ALTLOG during a session, using an OPTIONS statement, but that suggestion was never implemented, and was not carried over into the new submission system. So I don't think there's much hope for that.
How do I use the Altlog option if I want to set a designated pathway?
%let dira=%str(Pathway);
proc altlog="&dira.\Citgo_GA_&StartTime1..txt".log;
run;
The code didn't work
It's not a PROC, it's a system option. The system option needs to be set before your SAS session starts. How to set the system option depends on your environment. If your SAS session is running on a server, you would likely need to ask your server admin to change the setting. If your SAS session is running on your PC ("Windows SAS"), then you should be able to set it yourself, in the config file or in the command that starts your SAS session.
As you mentioned (and as described in the documentation), ALTLOG is an option, not a procedure. As you can also see in the documentation, it has to be set at SAS invocation, either from the commandline or in the configuration file(s). You cannot set it from code. If you want to have a log file of all actions done in a workspace server session (which is the backend for Enterprise Guide and SAS Studio), while also keeping your client-side log, you have to configure server-side logging accordingly. This is done in the logconfig.xml file in the configuration tree of your SAS server.
Define two macros (store them in autoexec, or somewhere else):
%macro Before(path,fileref=L);
filename &fileref. "&path.";
proc printto log = &fileref. NEW;
run;
%mend Before;
%macro After(fileref=L);
proc printto;
run;
filename &fileref. list;
data _null_;
infile &fileref.;
input;
putlog _infile_;
run;
filename &fileref. clear;
%mend After;
And the run for example:
%Before(R:\file_for_log.txt)
/* your code goes here, e.g. */
data new_darta;
set sashelp.class;
age_plus_2 = AGE + 2;
run;
%After()
You will get the following log and the file "R:\file_for_log.txt
" too:
1 %Before(R:\file_for_log.txt)
NOTE: PROCEDURE PRINTTO used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: Fileref= L
Physical Name= R:\file_for_log.txt
NOTE: The infile L is:
Filename=R:\file_for_log.txt,
RECFM=V,LRECL=32767,File Size (bytes)=593,
Last Modified=27Feb2024:21:29:13,
Create Time=27Feb2024:21:26:12
NOTE: PROCEDURE PRINTTO used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
2
3 /* your code goes here, e.g. */
4 data new_darta;
5 set sashelp.class;
6 age_plus_2 = AGE + 2;
7 run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.NEW_DARTA has 19 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
8
9
10 %After()
NOTE: 23 records were read from the infile L.
The minimum record length was 0.
The maximum record length was 70.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
NOTE: Fileref L has been deassigned.
Bart
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.