DATA Step, Macro, Functions and more

Logparm directive for sysin filename???

Accepted Solution Solved
Reply
Super Contributor
Posts: 376
Accepted Solution

Logparm directive for sysin filename???

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


Accepted Solutions
Solution
‎01-21-2012 03:51 AM
Valued Guide
Posts: 2,175

Logparm directive for sysin filename???

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

View solution in original post


All Replies
Frequent Contributor
Posts: 101

Logparm directive for sysin filename???

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;

Solution
‎01-21-2012 03:51 AM
Valued Guide
Posts: 2,175

Logparm directive for sysin filename???

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

Super Contributor
Posts: 376

Logparm directive for sysin filename???

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.

Super Contributor
Posts: 376

Logparm directive for sysin filename???

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

Super Contributor
Posts: 376

Logparm directive for sysin filename???

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 536 views
  • 0 likes
  • 3 in conversation