BookmarkSubscribeRSS Feed
ScottBass
Rhodochrosite | Level 12

Hi,

SAS 9.3 on Windows

My config file contains:

-log           E:\Logs\Some\Path\Sysin_Filename_

-logparm       "rollover=session"

with upstream config file directives to timestamp the logfile as Sysin_Filename_YYYYMMDD_HHMMSS.log

Is there a way to make SAS "self-aware" about the actual log filename it's writing to?

%sysfunction(getoption(log)) returns E:\Logs\Some\Path\Sysin_Filename_, not the timestamped log filename.

I want to put the actual log filename in a SAS generated email message when an error occurs.

Two ways that I think will work:

  • Search the logs directory for the latest version of the log file.
  • Use trickery with handle.exe to get the SAS command line, which will reveal the actual log filename.

But I was hoping there's a more obvious less kludgy approach.


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.
2 REPLIES 2
AndrewHowell
Moderator

Hi - if you know the folder where the log file is created, you could use the dread() and associated functions to find the latest file in that folder, or the log file that matches the &SYSDATE & SYSTIME values? Not an exact answer, but might get you what you want. Just a thought..

ScottBass
Rhodochrosite | Level 12

FYI, here's the approach I'm currently using.  Credit for the original code (slight modifications by me) goes to M. Dixon of Selerity.

Let me know if you think there's a better approach...

* capture the timestamped log filename ;

filename cmd pipe "handle -p &SYSJOBID";

data _null_;

  infile cmd;

  input;

  * delete unwanted lines ;

  if not prxmatch("#\.log(_\d+)*$#io",strip(_infile_)) then delete;

  if prxmatch("#\\arm#io",strip(_infile_)) then delete;

  * capture log file ;

re=prxparse("#.*([a-zA-Z]:.*\.log(_\d+)*$)#o");

  if prxmatch(re,strip(_infile_)) then log=prxposn(re,1,strip(_infile_));

  call symputx("log",log,"G");

  stop;

run;

filename cmd clear;

As per my original post, I think SAS should make this a bit easier...


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
  • 2 replies
  • 1470 views
  • 3 likes
  • 2 in conversation