Hello All,
We currently have a log scan program deployed that goes to the folder where our job logs are created and pulls in the text from each log. We then search for error, warning, etc ...
The problem we are running into is how to pull the most current log files without coming across ones that are currently being created / open. When this occurs it kills the load ---
Is there anyway to skip files that are in use and have the program continue running?
Thanks,
Andrew
If your environment is Windows, this old macro will work. I guess it works in Unix/Linux also, because the sas file functions are general, but i cannot try it.
/********************************************************************************/
/* CheckExtFile Erik Lund-jensen 21 jan 2011 */
/* Macro to check if an external file can be accessed */
/* Use in macro: %if %CheckExtFile(file) then ...; */
/* Use in Data Step: if %CheckExtFile(file) then ...; */
/* Return value: -1 = file exists, but is locked by another process */
/* 0 = file does not exist */
/* 1 = fil can be opened for read access */
/* parm to macro is file name (full path). */
/********************************************************************************/
%macro CheckExtFile(inputfil);
%local fil_findes rc filid;
%* Check if file exists;
%let fil_findes = %sysfunc(fileexist(&inputfil));
%if &fil_findes = 1 %then %do;
%* Check if it can be opened;
%let rc=%sysfunc(filename(filref,&inputfil));
%let filid=%sysfunc(fopen(&filref));
%if &filid > 0 %then %do;
%let filcheck = 1;
%* Close again, if it could be opened;
%let rc=%sysfunc(fclose(&filid));
%end;
%else %let filcheck = -1;
%end;
%else %let filcheck = 0;
%* No semikolon after following statement!;
%eval(&fil_findes)
%mend;
You should specify your operating enviorment and configuration for this type of question as some suggestions are likely to be Operating system dependent.
If your environment is Windows, this old macro will work. I guess it works in Unix/Linux also, because the sas file functions are general, but i cannot try it.
/********************************************************************************/
/* CheckExtFile Erik Lund-jensen 21 jan 2011 */
/* Macro to check if an external file can be accessed */
/* Use in macro: %if %CheckExtFile(file) then ...; */
/* Use in Data Step: if %CheckExtFile(file) then ...; */
/* Return value: -1 = file exists, but is locked by another process */
/* 0 = file does not exist */
/* 1 = fil can be opened for read access */
/* parm to macro is file name (full path). */
/********************************************************************************/
%macro CheckExtFile(inputfil);
%local fil_findes rc filid;
%* Check if file exists;
%let fil_findes = %sysfunc(fileexist(&inputfil));
%if &fil_findes = 1 %then %do;
%* Check if it can be opened;
%let rc=%sysfunc(filename(filref,&inputfil));
%let filid=%sysfunc(fopen(&filref));
%if &filid > 0 %then %do;
%let filcheck = 1;
%* Close again, if it could be opened;
%let rc=%sysfunc(fclose(&filid));
%end;
%else %let filcheck = -1;
%end;
%else %let filcheck = 0;
%* No semikolon after following statement!;
%eval(&fil_findes)
%mend;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: