Hi,
SAS 9.2 on Windows
LOGPARM= doc: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002303556.htm
LOG= doc: http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#win-sysop-log.htm
What I want to do is create a config file to set the desired options for our ETL batch processing.
Say my program name is Foo.sas.
Now, I can say -log Q:\Path\To\Log\File\Directory to create Q:\Path\To\Log\File\Directory\Foo.log.
And I can say -log Q:\Path\To\Log\File\Directory\Foo_%Y%m%d_%H%M.log ON THE COMMAND LINE to create a timestamped log.
But, how can I create a timestamped log via a config file?
What I want is something like -log Q:\Path\To\Log\File\Directory\%P_%Y%m%d_%H%M.log, where %P resolves to the name of the -sysin program name.
I don't see a %P log directive, which seems to me a glaring omission from the list of log directives.
Is there any way to have a *static* configuration file with a -log option that will allow me to create a timestamped log in a specified directory path?
Thanks,
Scott
Scott
If you invoke the SAS session from another SAS session or from a script or bat file, use an environment variable to hold the name of the target of the SASIN that you want to appear in the Log file name. When resolving a config file SAS resolves !name as a script resolves %name% with the value of environment variable "name".
Then you can have a config file with a mixture of LOGPARM directives and your !sysin_name environment variable.
Does that provide the flexibility you need?
Peter
You can use PROC PRINTTO to reroute your log to another file and use macro variables to dynamically generate the log name and timestamp. For example, copy the code below and save it to a file called foo.sas, modify the path in the filename statment if you wish, run it in batch and see if does what you wanted it to do. You can put the code in an autoexec.bat if you want to make it available to other programs.
%let tmstmp = %sysfunc( putn( %sysfunc( date() ), yymmddn8. ))_%sysfunc( compress( %sysfunc( putn( %sysfunc( time() ), tod5. )), ':' ));
%let prog = %scan( %scan( %sysfunc( dequote( %scan( &sysprocessname, -1, %str( ) ))), -1, \ ), 1, . );
filename mylog "c:\temp\&prog._&tmstmp..log";
proc printto log=mylog;
run;
Scott
If you invoke the SAS session from another SAS session or from a script or bat file, use an environment variable to hold the name of the target of the SASIN that you want to appear in the Log file name. When resolving a config file SAS resolves !name as a script resolves %name% with the value of environment variable "name".
Then you can have a config file with a mixture of LOGPARM directives and your !sysin_name environment variable.
Does that provide the flexibility you need?
Peter
Hi,
I sent an email to suggest@sas.com; SAS replied that it was a good suggestion and would add it to the SAS 9.4 list and the SASWare ballot. I was hoping for a back port to SAS 9.3 via a hotfix - we shall see.
For now, I'll invoke our nightly ETL processing using a script, setting an environment variable for the sysin program name, then reference the environment variable in the config file.
This will make maintenance of the log file path and log filename a lot easier the -log command line option on tens/hundreds of individual program scheduler entries.
Thanks for the suggestion Peter.
Scott
P.S.: I'm hoping SAS will resolve something like: -log Q:\Path\To\Log File\Directory\!progname_%Y%m%d_%H%M.log appropriately (as yet untested). If the combination of environment variable and logparm directives confuses SAS, I'll need to create the complete logfilename environment variable in the calling script. I'm going to switch from .bat/.cmd file scripting to PowerShell, which will make creating that environment variable much easier than the antiquated and klunky DOS batch language.
Hi,
I just thought of another issue...
Say I want to post-process the log file from my calling script, say to grep the log for errors. In pseudocode (not an actual Windows batch file!):
sas -sysin myjob.sas -log C:\Logs\myjob_%Y%m%d_%H%M.log
if %ERRORLEVEL% ne 0 then do;
grep ^ERROR: C:\Logs\???.log
end;
where sysout gets captured by my scheduling tool (Control-M). Or, say I redirect the grep output and attach the log excerpt to an email.
AFAIK, if the config file logging directives are what caused SAS to add the date/time stamp to the log filename, there is no way for the calling script to know what the logfile name was.
The nice thing about having this configured via a config file is:
* One single place to configure and maintain this setting
* I would get the desired results whether I invoked SAS via my wrapper script or not.
However, in this scenario, I might need to make the calling script derive the timestamped log filename before invoking SAS, and abandon the use of logging directives via the config file.
Thoughts?
Thanks,
Scott
Hi All,
Thanks for the replies. I'll send an enhancement request to SAS. It astonishes me that there are logparm directives for, say, the node name, process id, or unique identifier, but not one for the sysin filename of a batch program!!!
Regards,
Scott
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.