<?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: Need a SAS Macro to delete 5 days older files from folder. in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Need-a-SAS-Macro-to-delete-5-days-older-files-from-folder/m-p/280171#M7953</link>
    <description>Check out the external files function category.&lt;BR /&gt;Is the date reflected on the file name? &lt;BR /&gt;If not, you need to extract file attribute information.</description>
    <pubDate>Sat, 25 Jun 2016 22:15:50 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2016-06-25T22:15:50Z</dc:date>
    <item>
      <title>Need a SAS Macro to delete 5 days older files from folder.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Need-a-SAS-Macro-to-delete-5-days-older-files-from-folder/m-p/280157#M7952</link>
      <description>&lt;P&gt;I need to delete 5 days older log files from a folder.I need to do from SAS EG and need a SAS macro.Unix command not required only SAS coding.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jun 2016 16:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Need-a-SAS-Macro-to-delete-5-days-older-files-from-folder/m-p/280157#M7952</guid>
      <dc:creator>tarunchitkara</dc:creator>
      <dc:date>2016-06-25T16:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: Need a SAS Macro to delete 5 days older files from folder.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Need-a-SAS-Macro-to-delete-5-days-older-files-from-folder/m-p/280171#M7953</link>
      <description>Check out the external files function category.&lt;BR /&gt;Is the date reflected on the file name? &lt;BR /&gt;If not, you need to extract file attribute information.</description>
      <pubDate>Sat, 25 Jun 2016 22:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Need-a-SAS-Macro-to-delete-5-days-older-files-from-folder/m-p/280171#M7953</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-06-25T22:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Need a SAS Macro to delete 5 days older files from folder.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Need-a-SAS-Macro-to-delete-5-days-older-files-from-folder/m-p/280172#M7954</link>
      <description>&lt;P&gt;I don't know of a way to extract file information without using Unix functions &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FDELETE will delete files once you identify them though.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This really is a job for a clean up script though, similar to cleanwork utility from SAS. Probably worth looking at to see if it can help you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/hostunx/67929/HTML/default/viewer.htm#n13ozwpq7az8v6n1s77r8c2zp9d1.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/hostunx/67929/HTML/default/viewer.htm#n13ozwpq7az8v6n1s77r8c2zp9d1.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jun 2016 23:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Need-a-SAS-Macro-to-delete-5-days-older-files-from-folder/m-p/280172#M7954</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-25T23:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need a SAS Macro to delete 5 days older files from folder.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Need-a-SAS-Macro-to-delete-5-days-older-files-from-folder/m-p/280192#M7955</link>
      <description>&lt;P&gt;You can easily get a directory listing in either of two ways:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Use e.g. the code as in this &lt;A href="http://www.wuss.org/proceedings12/55.pdf" target="_blank"&gt;2012 SGF paper&lt;/A&gt;. The trick is to assign a filename to a directory:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mydir "/my/logdir";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will allow you to get filenames and filter them. Caveat here is that on Linux the FINFO() does not give you a creation date.&amp;nbsp; So it is required that the filename contains a date- and timestamp (which is a good habit for log files anyway). If so, parse the filename and use FDELETE() if it matches the 5-day criterium.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Use the Linux command ls in a pipe:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename dirlist pipe "ls -l yourlogdir" ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Many variations can be chosen even up to use of find with the mtime / ctime options to directly only return the files older than 5 days. And heck, find can even delete them so SAS will not be involved at all. But this seems to be against your requirement of not using Linux commands. Also it could be that your workspace server run with -noxcmd, defeating this option entirely.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So easiest way would be to challenge the "no Linux command" restriction. Otherwise let's hope a date and time are in the filename.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jun 2016 10:44:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Need-a-SAS-Macro-to-delete-5-days-older-files-from-folder/m-p/280192#M7955</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-06-26T10:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need a SAS Macro to delete 5 days older files from folder.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Need-a-SAS-Macro-to-delete-5-days-older-files-from-folder/m-p/280194#M7956</link>
      <description>Thank you very much jan.</description>
      <pubDate>Sun, 26 Jun 2016 11:11:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Need-a-SAS-Macro-to-delete-5-days-older-files-from-folder/m-p/280194#M7956</guid>
      <dc:creator>tarunchitkara</dc:creator>
      <dc:date>2016-06-26T11:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need a SAS Macro to delete 5 days older files from folder.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Need-a-SAS-Macro-to-delete-5-days-older-files-from-folder/m-p/427513#M13172</link>
      <description>&lt;P&gt;Here's an approach that doesn't require the server to have X command enabled.&amp;nbsp; This could be done in one step, but I'm a fan of using generic macros so I'll do that to get my directory listing first.&amp;nbsp; Two choices for doing this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* &lt;A href="http://www.sascommunity.org/wiki/Filelist_macro" target="_self"&gt;Filelist&lt;/A&gt; macro (Don Henderson)&lt;/P&gt;&lt;P&gt;* &lt;A href="https://github.com/Boemska/macrocore/blob/master/base/mp_dirlist.sas" target="_self"&gt;mp_dirlist&lt;/A&gt; macro (yours truly)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now we have a list of filepaths, we can use the `finfo` function to find the last modified date, convert it to a datetime (using a trusty anydtdtme informat), compare the age, and delete as appropriate!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set work.mp_dirlist;
  drop rc fid close;
  format modified_dttm datetime19.;
  rc=filename("fref",filepath);
  fid=fopen("fref");
  if fid&amp;gt;0 then do;
    modified=finfo(fid,"Last Modified");
    modified_dttm=input(modified,anydtdtm24.);
  end;
  close=fclose(fid);&lt;BR /&gt;  /* 60secs * 60 mins * 24 hours * 5 days */
  if modified_dttm&amp;gt;0 and datetime()-modified_dttm &amp;gt; (60*60*24*5) /* and ext='???'*/ then do;
    putlog 'deleting' filename;
    rc=fdelete("fref");
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jan 2018 14:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Need-a-SAS-Macro-to-delete-5-days-older-files-from-folder/m-p/427513#M13172</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2018-01-14T14:04:57Z</dc:date>
    </item>
  </channel>
</rss>

