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

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 ? 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
AllanBowe
Barite | Level 11

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

 

/Allan
MacroCore library for app developers
Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs

View solution in original post

2 REPLIES 2
AllanBowe
Barite | Level 11

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

 

/Allan
MacroCore library for app developers
Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
learn_SAS_23
Pyrite | Level 9

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)

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1249 views
  • 2 likes
  • 2 in conversation