Hi Guys,
I wondered if someone could help me, i want every Base SAS session to output their log to a location
If i use the following in the sasV9.cfg file:
-ALTLOG "D:\SAS_Logs\%username%.txt
It correctly creates me a log with my current username in the location.
However as there could be multiple sessions and i don't want them overwriting i wanted to add parameters such as date, time, host name however nothing seems to work inside the cfg file, Both SAS and Windows variables do not work:
-ALTLOG "D:\SAS_Logs\%username%_%Y_%m_%d_%H_%M.txt"
-ALTLOG "D:\SAS_Logs\%username%_%computername%_%date%_%time%.txt"
Can anyone tell me is it possible to use the AltLog with additional parameters?
I have made it work by using a .bat file to Launch the SAS application thus:
@echo off
set dt=%date%
set newdate=%dt:~6,4%%dt:~3,2%%dt:~0,2%
set mytime=%time%
set mytime=%mytime::=%
set mytime=%mytime:.=_%
set stamp=%newdate%_%mytime% echo %stamp% "D:\SASHome\SASFoundation\9.4\sas.exe" -CONFIG "D:\SASHome\SASFoundation\9.4\nls\en\sasv9.cfg" -ALTLOG "D:\SAS_Logs\%username%_%computername%_%stamp%.log"
The above works but i would prefer it is native inside the Config File but if not i can use the above, just wondered if i am missing something?
EDIT: I tweaked my Batch a bit having read a few articles so I could insert Seconds/MS in to ensure uniqueness. Updated Code above
Hi @srapp88, I've used this in my config which is close to what you are looking for:
-altlog "C:\temp\#l_#n_#Y-#m-#d_#H-#M_#v.log"
-logparm "rollover=session"
The #v generates a unique identifier (on Windows the process id + a sequence number).
You can see all the parameters in the LOGPARM doc
Dave
Hi @srapp88, I've used this in my config which is close to what you are looking for:
-altlog "C:\temp\#l_#n_#Y-#m-#d_#H-#M_#v.log"
-logparm "rollover=session"
The #v generates a unique identifier (on Windows the process id + a sequence number).
You can see all the parameters in the LOGPARM doc
Dave
This is exactly what i need!
so what i was missing was the -logparm part as i had the AltLog but that never worked, adding Log Parm it is fine.
Thank you very much! I can now avoid having to use a batch script to Launch SAS.
Thanks all for your responses 🙂
@srapp88 wrote:
Hi Guys,
I wondered if someone could help me, i want every Base SAS session to output their log to a location
If i use the following in the sasV9.cfg file:
-ALTLOG "D:\SAS_Logs\%username%.txt
It correctly creates me a log with my current username in the location.
However as there could be multiple sessions and i don't want them overwriting i wanted to add parameters such as date, time, host name however nothing seems to work inside the cfg file, Both SAS and Windows variables do not work
A "outside-the-box" alternative to prevent logs from overwriting each other is to use PROC PRINTTO in each program, you can then specify a unique name in the program and then the logs don't overwrite.
This also has the benefit of allowing you to name the SASLOGs in a understandable fashion, instead of the username/node/year/month/day/hour/minute name on the SASLOG as suggested by @DaveHorne. For example, if you are working on Project ABC and executing code from a program named program1.sas, you could have the SASLOG named Project_ABC_program1.log instead of username/node/year/month/day/hour/minute naming. You could also append a date and time and unique Id in the name of the log if desired.
Agree, the flexibility offered by PROC PRINTTO is nice. You can use macros or whatever to find all the information you might want to use in the name (current program name, userid, date/time, guid, etc etc.).
The only downside is that when you redirect your log in an interactive session, you don't get to see it without jumping through hoops (like reading it back in). I really wish you could specify ALTLOG on an options statement. If you agree, I'm trolling for upvotes on my aging ballotware item:
@Quentin wrote:
The only downside is that when you redirect your log in an interactive session, you don't get to see it without jumping through hoops (like reading it back in).
I don't know what this means. Can you explain?
When I run PROC PRINTTO, I can look at the log while the program is running via any text editor.
@PaigeMiller wrote:
@Quentin wrote:
The only downside is that when you redirect your log in an interactive session, you don't get to see it without jumping through hoops (like reading it back in).
I don't know what this means. Can you explain?
When I run PROC PRINTTO, I can look at the log while the program is running via any text editor.
Agree, when running a job and redirecting the log, you can look at it while it's running with an editor.
I mean in an interactive session where I want to see the log in the IDE. Suppose I'm running an interactive session in DM SAS or EG or Studio. I want to be able to run code and see the log displayed in the IDE, and also have the log written to a permanent file. For that, I wish I could just use options ALTLOG... to start writing my log to a file. If I used PROC PRINTTO to send it to a file, it doesn't get displayed in the IDE.
So sometimes in EG I will hack something like:
filename mylog "c:\logs\mylog.log";
*redirect log to a file;
proc printto log=mylog new;
run;
*main code here;
proc printto log=log; *reset;
run;
*write logfile back to the IDE log;
data _null_;
infile mylog;
input;
put _infile_;
run;
@Quentin wrote:
I mean in an interactive session where I want to see the log in the IDE. Suppose I'm running an interactive session in DM SAS or EG or Studio. I want to be able to run code and see the log displayed in the IDE, and also have the log written to a permanent file. For that, I wish I could just use options ALTLOG... to start writing my log to a file. If I used PROC PRINTTO to send it to a file, it doesn't get displayed in the IDE.
What does IDE mean?
Hi @ruturaj72, I checked the 9.3 doc on LOGPARM and the options appear the same. The only time I've seen the situation you describe is when I forget the ROLLOVER option. If that looks ok then you may need to open a track with tech support.
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!
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.