<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Skip reading files that are being written to in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Skip-reading-files-that-are-being-written-to/m-p/709383#M218127</link>
    <description>&lt;P&gt;As much as I remember SAS adds a suffix&amp;nbsp;&lt;STRONG&gt;.lck&lt;/STRONG&gt; to locked files, any how I'm not sure is it done to log files too. It may depend on OS.&lt;/P&gt;
&lt;P&gt;Check the directory where logs are kept and see if there are files with suffix&amp;nbsp;&lt;STRONG&gt;.log.lck&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;or&amp;nbsp;&lt;STRONG&gt;.loglck&lt;/STRONG&gt; or alike.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, if you need read only the log (not writing to it) maybe you can &lt;STRONG&gt;open&lt;/STRONG&gt; it&lt;/P&gt;
&lt;P&gt;with the &lt;STRONG&gt;READONLY&lt;/STRONG&gt; option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Jan 2021 08:40:45 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2021-01-05T08:40:45Z</dc:date>
    <item>
      <title>Skip reading files that are being written to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-reading-files-that-are-being-written-to/m-p/709373#M218122</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been getting this error when reading a list of log files. Some of them can be 'hot' running some house cleaning at the background.&lt;/P&gt;&lt;P&gt;Instead of bombing out each time, is there a way to know which one is currently being written to so that I can skip reading it altogether? Or any other approach as long as SAS EG won't error out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Resource is write-locked by another user. File=/somepath/abc_yymmdd.log. System Error Code = 11.&lt;BR /&gt;ERROR: File is in use, /somepath/abc_yymmdd.log.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 06:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-reading-files-that-are-being-written-to/m-p/709373#M218122</guid>
      <dc:creator>AWHT</dc:creator>
      <dc:date>2021-01-05T06:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Skip reading files that are being written to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-reading-files-that-are-being-written-to/m-p/709383#M218127</link>
      <description>&lt;P&gt;As much as I remember SAS adds a suffix&amp;nbsp;&lt;STRONG&gt;.lck&lt;/STRONG&gt; to locked files, any how I'm not sure is it done to log files too. It may depend on OS.&lt;/P&gt;
&lt;P&gt;Check the directory where logs are kept and see if there are files with suffix&amp;nbsp;&lt;STRONG&gt;.log.lck&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;or&amp;nbsp;&lt;STRONG&gt;.loglck&lt;/STRONG&gt; or alike.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, if you need read only the log (not writing to it) maybe you can &lt;STRONG&gt;open&lt;/STRONG&gt; it&lt;/P&gt;
&lt;P&gt;with the &lt;STRONG&gt;READONLY&lt;/STRONG&gt; option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 08:40:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-reading-files-that-are-being-written-to/m-p/709383#M218127</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-05T08:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Skip reading files that are being written to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-reading-files-that-are-being-written-to/m-p/709384#M218128</link>
      <description>&lt;P&gt;I assume that you are reading a number of files in a single data step, and that the whole thing crashes when one of the files are not available.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the way to go is to use the FOPEN or MOPEN function. That should just return a zero if the file is not available for reading, in which case you can use the SYSRC() and SYSMSG() functions to see what went wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance, if you are reading all the .log files from a specific directory, it can be done something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename logdir 'c:\saslogs';

data loglines;
  dir_id=dopen('logdir');
  if dir_id=0 then do;
    msg=sysmsg();
    put msg=;
    stop;
    end;
  do _N_=1 to dnum(dir_id);
    filename=dread(dir_id,_N_);
    if upcase(scan(filename,-1,'.'))='LOG' then do;
      file_id=mopen(dir_id,_N_);
      if file_id=0 then do;
        msg=sysmsg();
        put filename= msg=;
        end;
      else do;
         /* code to read the file, one option is to use FREAD and FGET: */
         do line_no=1 by 1 while(fread(file_id)=0);
           length line $200;
           rc=fget(file_id,line);
           output;
           end;
         rc=fclose(file_id);
         end;
      end;
    end;
  rc=dclose(dir_id);
  drop dir_id file_id rc;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, you may want to replace the OUTPUT statement with some more advanced processing of the log line, such as looking for errors or warnings, and only outputting those.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 08:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-reading-files-that-are-being-written-to/m-p/709384#M218128</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2021-01-05T08:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: Skip reading files that are being written to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Skip-reading-files-that-are-being-written-to/m-p/709386#M218130</link>
      <description>&lt;P&gt;Log files do not have an additional .lck extension when being written to, and, at least on UNIX, SAS does not have the file locked while it is used, as you can always read it while the program is still running.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 10:16:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Skip-reading-files-that-are-being-written-to/m-p/709386#M218130</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-05T10:16:48Z</dc:date>
    </item>
  </channel>
</rss>

