BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
srapp88
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
DaveHorne
SAS Employee

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

View solution in original post

10 REPLIES 10
DaveHorne
SAS Employee

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

srapp88
Calcite | Level 5

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 🙂

PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Quentin
Super User

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:

 

https://communities.sas.com/t5/SASware-Ballot-Ideas/Allow-ALTLOG-to-be-specified-on-OPTIONS-statemen...

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Quentin
Super User

@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;
BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Quentin
Super User
An IDE is an Integrated Development Environement. See https://en.m.wikipedia.org/wiki/Integrated_development_environment

So SAS Display Manager also known as “PC SAS” or “Windows SAS” is an IDE. Enterprise Guide and SAS Studio are also IDEs.

—Q.
BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
ruturaj72
Fluorite | Level 6
@DaveHorne

Hey Deve,

I tried the two lines in sasv9_local.
But logs are generating with the special characters not with the timestamp.

Please help me out.
Os : aix.
Sas version 9.3
DaveHorne
SAS Employee

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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