I have a scheduled job running on the Schedule Manager. I'm not able to access the log file so I routed the AltLog to a place I can get to. I want to add the date and time parameters to the log file so I modified my batch command like this:
/opt/sas/sascompute/config/Lev1/SASApp/BatchServer/sasbatch.sh -log /opt/sas/sascompute/config/Lev1/SASApp/BatchServer/Logs/Testing_JeffB_AltLog_AltLog_Testing_ -batch -noterminal -altlog /opt/sas/data/sas_imi_reports/Testing/JeffB/AltLog/Altlog_#H#M.log -logparm "rollover=session" -sysin /opt/sas/data/sas_imi_reports/scheduler/AltLog_Testing.sas
The problem is instead of getting the hour and month of in the log file I get the a file literally named Altlog_#H#M.log
What am I missing?
Thank you SAS friends,
Well, crud. It was worth a shot, I suppose. "#" typically works best on Windows, but "%" I've used successfully for Linux/Posix/Unix. I just looked at one that I'm using: -log I:\commercial\%env%\pgm\logs\0_CSI_Sus_#Y-#m-#d_#H-#M-#s_#p.log
It's a -log not -altlog, but they should work the same. Your log directives look like mine, so I don't see why they're not working. One note: There is a difference between #M (current minutes) and #m (current month), but since none of the log directives are working, I don't suppose that matters much right now.
If you were generating the statements with a program, I'd suggest just coding things with a script or with SAS, but I don't think you can do that here.
Perhaps @gwootton can provide us with further insight.
Now, that looks like Unix/Linux/Posix syntax. Is there something that would work with Windows? In particular, I want something that can put the Process ID into the log file name via an -altog for a SAS Connect session (i.e. submitted via RSUBMIT). #p doesn't work (no log directives work as far as I have been able to determine).
options sascmd="!sascmd"; signon test; rsubmit; filename testlog "C:\Temp\test_&sysjobid..log"; proc printto log=testlog; run; proc setinit; run; endrsubmit; signoff test;
An excellent idea, and one I'm pretty sure would work. The only drawback to PROC PRINTTO is that then the logs from the sub-processes will not get brought into the main log. Maybe I can live with that, but I'll have to think about it.
The advantage of ALTLOG is that I can "have my cake and eat it too." I get an individual sub-process log which is super helpful in debugging or monitoring long-running, complex jobs, and at end of job I get a single, consolidated log containing not only the supervisor process log but all all of the sub-process logs.
My code looks like this:
%LET Pgm = 2_CSI_CPT_Related_Suspects; %LET Process_Name = CPT_Rela; %LET &Process_Name._RC = 0; %LET Cmd_String = !sascmdv -logparm 'write=immediate rollover=session' -memsize 8G -altlog &Log_Path\sub_process_logs\&Pgm._%Get_Date(FORMAT=YYMMDDD10)_%Get_Time(FORMAT=b8601tm6).log; *-altlog &Log_Path\sub_process_logs\&Pgm._#Y-#m-#d_#H-#M-#s_#p.log; %PUT &Nte2 &=Cmd_String; OPTION SASCMD = "&Cmd_String"; OPTION REMOTE = &Process_Name; %SYSLPUT _CLIENTTASKLABEL = &Pgm; %SYSLPUT Process_Name = &Process_Name; %SYSLPUT Prompt = &Prompt; %SYSLPUT Pgm = &Pgm; %SYSLPUT Pgm_Path = &Pgm_Path; %SYSLPUT Environment = &Environment; RSUBMIT PROCESS=&Process_Name WAIT=NO PERSIST=NO; %INC "&Pgm_Path\&Pgm..sas"; ENDRSUBMIT; %Check_RC (MsgLvl=&MsgLvl, ErrLvl=&ErrLvl, Email=&Email, Err=&Err, FROM=&From, TO=&To, SUBJ=&Subj, Debug=&Debug, Trace=&Trace, CC1=&CC1, CC2=&CC2, CC3=&CC3, CC4=&CC4, CC5=&CC5, CC6=&CC6, CC7=&CC7, CC8=&CC8, CC9=&CC9, Msg1=&Msg1, Msg2=&Msg2, Msg3=&Msg3, Msg4=&Msg4, Msg5=&Msg5, Msg6=&Msg6);
You can see where I've tried the -altlog with the log directives, but all of the log directives are placed as literals in the name of the log file (not very helpful). The code above gives me date and time, which isn't bad, but when I'm looking at the Processes in Task Manager, it would be really nice to have the Process ID embedded in the log file name so I'd know which log file corresponded to which process in Task Manager without having to open each log. Sometimes I'll be running a dozen or so sub-processes, and it's a bit of a hassle to go opening log files until I find the one I want. I was hoping there was something slick available like what you shared with @SAShole. 🙂
Well we can't know the PID until the session starts, but date and time we can pull from functions into a macro variable.
%let suffix = %sysfunc(date(),YYMMDDn8.)_%sysfunc(compress(%sysfunc(time(),time.),%str( :))); options sascmd="!sascmd -altlog C:\Temp\altlog_&suffix..log"; signon test; rsubmit; proc setinit; run; endrsubmit; signoff test;
It's interesting that regular batch SAS submission knows how to emplace the PID in the log file name even though the PID isn't known at the time of instanciation but SAS Connect cannot.
So I guess my choices are:
a) Continue to use Altlog and just deal with it that I can't have PID in my sub-process log file names
b) Use Proc PRINTTO and accept the loss of the sub-process logs from the main log file.
That worked! Thanks!
Oddly enough though, when I add this code to a job that runs every morning, no long file is generated. Do you know why that could be? Does the order of the parameters in the command line matter? Is my filename too long? I can't think of what else it could be?
-altlog /opt/sas/data/sas_reports_analytics/scheduler/filename_vs_filename_$(date +%Y-%m-%d_%H%M%S).log
The SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment.
Learn how to install the SAS Viya CLI and a few commands you may find useful in this video by SAS’ Darrell Barton.
Find more tutorials on the SAS Users YouTube channel.