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

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


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
1 ACCEPTED SOLUTION

Accepted Solutions
Peter_C
Rhodochrosite | Level 12

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

5 REPLIES 5
FloydNevseta
Pyrite | Level 9

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;

Peter_C
Rhodochrosite | Level 12

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

ScottBass
Rhodochrosite | Level 12

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.


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
ScottBass
Rhodochrosite | Level 12

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


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
ScottBass
Rhodochrosite | Level 12

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


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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