How to create a log file per session with below command with &sysjobid
%let Log_file_name =%sysfunc(compress(%scan(&_program,-1,/)_&sysjobid._%sysfunc(datetime(),b8601dt))).log ;
%let LogOutFile = &Test_path./&Log_file_name.;
filename stplog "&LogOutFile.";
proc printto log=stplog;
run;
But it creates log files , with same sysjobid with different times
Test_STP_8628_20210922T173146.log
Test_STP_8628_20210922T173144.log
In practice , where my program runs distributed across servers and runs parallel in same time , Can &sysjobid will differ and create different log files ?
The `sysjobid` is the PID and it CAN be the same across multiple sessions.
Your question is confusing as you ARE creating different log files per process / session due to the use of a timestamp. To ensure uniqueness though, you might want to use a random number as well, as shown here: https://core.sasjs.io/mf__uid_8sas_source.html
For even better uniqueness you can use the `uuidgen()` function as shown in this macro: https://core.sasjs.io/mf__getuniquename_8sas.html
The `sysjobid` is the PID and it CAN be the same across multiple sessions.
Your question is confusing as you ARE creating different log files per process / session due to the use of a timestamp. To ensure uniqueness though, you might want to use a random number as well, as shown here: https://core.sasjs.io/mf__uid_8sas_source.html
For even better uniqueness you can use the `uuidgen()` function as shown in this macro: https://core.sasjs.io/mf__getuniquename_8sas.html
Thanks ,We like to create log file per session (i mean when multiple time client programs calls STP , it should create separate STP log file ) , As the log file available from webserver logs are having less details (we can't able to debug what's wrong with STP) .
we can create log file with random number from below links
&today._&now._&sysjobid._%sysevalf(%sysfunc(ranuni(0))*999,CEIL)
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.