<?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 Find recent log file of a SAS Job in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413589#M279948</link>
    <description>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:)</description>
    <pubDate>Wed, 15 Nov 2017 09:04:29 GMT</pubDate>
    <dc:creator>Sandy10</dc:creator>
    <dc:date>2017-11-15T09:04:29Z</dc:date>
    <item>
      <title>Find recent log file of a SAS Job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413581#M279947</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;There is&amp;nbsp;a location where all log files of SAS Jobs gets stored (We have LINUX Env)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also there will be .err files created wheen the job is failed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The log files name will be like jobname_timestamp&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eg: Job name is J_LOAD&lt;/P&gt;&lt;P&gt;Timestamp -when the job runs&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log file name will be&lt;STRONG&gt; J_LOAD_20171115143219.log&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Error file name will be :&lt;STRONG&gt;&amp;nbsp;J_LOAD_20171115143219.err&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;So its like everytime a job runs , the log file gets created which will be unique because of timestamp.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to run a job based on the log file creation of its dependent job.&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 09:30:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413581#M279947</guid>
      <dc:creator>Sandy10</dc:creator>
      <dc:date>2017-11-15T09:30:51Z</dc:date>
    </item>
    <item>
      <title>Find recent log file of a SAS Job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413589#M279948</link>
      <description>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:)</description>
      <pubDate>Wed, 15 Nov 2017 09:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413589#M279948</guid>
      <dc:creator>Sandy10</dc:creator>
      <dc:date>2017-11-15T09:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Find recent log file of a SAS Job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413595#M279949</link>
      <description>&lt;P&gt;Ok, so let me re-pose your question to you:&lt;/P&gt;
&lt;P&gt;Without looking at the directory, tell me which is the latest file in that directory?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Me, if I you have access to command line interaction, I would do:&lt;/P&gt;
&lt;PRE&gt;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;&lt;/PRE&gt;
&lt;P&gt;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.&amp;nbsp; Then the first observation read is the one you want.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 10:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413595#M279949</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-15T10:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Find recent log file of a SAS Job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413598#M279950</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just gave an example of a log file. Its like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;J_ABC_20171115143219.log&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;J_LOAD_20171115143019.log&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;J_LOAD_20171115143219.log&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;SPAN&gt;J_ABC_20171114143219.log&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What I want is if I want to serach for recent log of J_LOAD SAS Job, then output will be&amp;nbsp;&lt;SPAN&gt;J_LOAD_20171115143219.log which is the recent log.&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I do &amp;nbsp;have access to c&lt;SPAN&gt;ommand line interaction&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 10:20:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413598#M279950</guid>
      <dc:creator>Sandy10</dc:creator>
      <dc:date>2017-11-15T10:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: Find recent log file of a SAS Job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413606#M279951</link>
      <description>&lt;P&gt;And have you tried what I posted, which does what you ask and puts to the log the latest filename sorted by filename?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 10:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413606#M279951</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-15T10:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Find recent log file of a SAS Job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413607#M279952</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can this be used for Linux as well?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 10:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413607#M279952</guid>
      <dc:creator>Sandy10</dc:creator>
      <dc:date>2017-11-15T10:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Find recent log file of a SAS Job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413610#M279953</link>
      <description>&lt;P&gt;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:&lt;/P&gt;
&lt;PRE&gt;filename tmp pipe 'dir "s:\temp\J_LOAD*.log" /b /o-n';
&lt;/PRE&gt;
&lt;P&gt;To match what runs on your OS.&amp;nbsp; The principal is exactly the same.&lt;/P&gt;
&lt;P&gt;Maybe (just guessing here, -r is reverse order i know that):&lt;/P&gt;
&lt;PRE&gt;filename tmp pipe 'ls "//temp/J_LOAD*.log" -r';&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can find help on the ls command here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.tecmint.com/15-basic-ls-command-examples-in-linux/" target="_blank"&gt;https://www.tecmint.com/15-basic-ls-command-examples-in-linux/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 10:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413610#M279953</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-15T10:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Find recent log file of a SAS Job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413612#M279954</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will check and update if it works here &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 10:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413612#M279954</guid>
      <dc:creator>Sandy10</dc:creator>
      <dc:date>2017-11-15T10:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Find recent log file of a SAS Job</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413627#M279955</link>
      <description>&lt;P&gt;Since you have a nicely sorting timestamp in your filename, this should do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let loc=/temp;
%let jobname=J_LOAD;

filename oscmd pipe "cd &amp;amp;loc.; ls &amp;amp;jobname.*.log|sort|tail -1";

data _null_;
infile oscmd;
input;
call symput('last_job_log',trim(_infile_));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Depending on your needs, you might want to operate on the contents of _infile_ (extract the timestamp, remove the filename extension).&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 12:23:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-recent-log-file-of-a-SAS-Job/m-p/413627#M279955</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-15T12:23:10Z</dc:date>
    </item>
  </channel>
</rss>

