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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

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;

View solution in original post

2 REPLIES 2
ballardw
Super User

You should specify your operating enviorment and configuration for this type of question as some suggestions are likely to be Operating system dependent.

 

ErikLund_Jensen
Rhodochrosite | Level 12

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;

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
  • 2485 views
  • 1 like
  • 3 in conversation