BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

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;
8 REPLIES 8
Tom
Super User Tom
Super User

@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;

 

ybz12003
Rhodochrosite | Level 12
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?
Quentin
Super User

See docs for altlog:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/hostwin/n02cl0iq0k1fmxn11p83yirplodk.htm#:~:t....

 

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.

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Quentin
Super User

@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.

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
ybz12003
Rhodochrosite | Level 12

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

Quentin
Super User

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.

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Kurt_Bremser
Super User

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.

yabwon
Onyx | Level 15

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

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 8 replies
  • 550 views
  • 2 likes
  • 5 in conversation