BookmarkSubscribeRSS Feed
Sandy10
Calcite | Level 5

Hi

There is a location where all log files of SAS Jobs gets stored (We have LINUX Env)

 

Also there will be .err files created wheen the job is failed. 

The log files name will be like jobname_timestamp

 

Eg: Job name is J_LOAD

Timestamp -when the job runs

 

Log file name will be J_LOAD_20171115143219.log

Error file name will be : J_LOAD_20171115143219.err

So its like everytime a job runs , the log file gets created which will be unique because of timestamp.

 

I have to run a job based on the log file creation of its dependent job.

How to check which is the recent log file of a particular SAS Job (All I have is SAS Job name based on which I have to find recent log file ) I dont want to parse entire logs directory as there will lots of log files created. 

 

Using SAS 9.4

 

Thanks in advance 🙂 

 

 

 

8 REPLIES 8
Sandy10
Calcite | Level 5
Hi There is a location where all log files of SAS Jobs gets stored (We have LINUX Env) Also there will be .err files created wheen the job is failed. The log files name will be like jobname_timestamp Eg: Job name is J_LOAD Timestamp -when the job runs Log file name will be J_LOAD_20171115143219.log Error file name will be : J_LOAD_20171115143219.err So its like everytime a job runs , the log file gets created which will be unique because of timestamp. I have to run a job based on the log file creation of its dependent job. How to check which is the recent log file of a particular SAS Job (All I have is SAS Job name based on which I have to find recent log file ) I dont want to parse entire logs directory as there will lots of log files created. Using SAS 9.4 Thanks in advance:)
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Ok, so let me re-pose your question to you:

Without looking at the directory, tell me which is the latest file in that directory?

 

Do you see what I mean here, without assessing the files which are present then you have to supply some logical means to guess the latest file.

 

Me, if I you have access to command line interaction, I would do:

filename tmp pipe 'dir "s:\temp\J_LOAD*.log" /b /o-n';

data _null_;
  infile tmp;
  length fname $2000;
  input fname $;
  if _n_=1 then put fname;
run;

What this does is run a bare directory listing back into your dataset, and uses the OS to sort the filenames (as you have done it correctly and put the date in a sortable format), I use the reverse sort /o means sort, n means by name, and the - means reverse.  Then the first observation read is the one you want.

Sandy10
Calcite | Level 5

Hi.

 

Thanks for your reply. But there will be many logs of the same SAS job (if there are multiple reruns) . I want to take the recent log of a SAS Job. And there will be many logs of different SAS Jobs.

 

I just gave an example of a log file. Its like below:

 

J_ABC_20171115143219.log

J_LOAD_20171115143019.log

J_LOAD_20171115143219.log

 J_ABC_20171114143219.log

 

What I want is if I want to serach for recent log of J_LOAD SAS Job, then output will be J_LOAD_20171115143219.log which is the recent log. 

I do  have access to command line interaction

RW9
Diamond | Level 26 RW9
Diamond | Level 26

And have you tried what I posted, which does what you ask and puts to the log the latest filename sorted by filename?

Sandy10
Calcite | Level 5

Hi

 

Can this be used for Linux as well?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Afraid I don't use Linux so can't tell you exactly, but Linux does have the ls command line code which can do similar, so you would need to change this line:

filename tmp pipe 'dir "s:\temp\J_LOAD*.log" /b /o-n';

To match what runs on your OS.  The principal is exactly the same.

Maybe (just guessing here, -r is reverse order i know that):

filename tmp pipe 'ls "//temp/J_LOAD*.log" -r';

 

You can find help on the ls command here:

https://www.tecmint.com/15-basic-ls-command-examples-in-linux/

Sandy10
Calcite | Level 5

Hi

 

I will check and update if it works here 🙂 Thanks 🙂

Kurt_Bremser
Super User

Since you have a nicely sorting timestamp in your filename, this should do:

%let loc=/temp;
%let jobname=J_LOAD;

filename oscmd pipe "cd &loc.; ls &jobname.*.log|sort|tail -1";

data _null_;
infile oscmd;
input;
call symput('last_job_log',trim(_infile_));
run;

Depending on your needs, you might want to operate on the contents of _infile_ (extract the timestamp, remove the filename extension).

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
  • 8 replies
  • 1349 views
  • 0 likes
  • 3 in conversation