<?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: Deleting SAS Datasets  older than 3 days. in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64388#M6500</link>
    <description>The values in the dictionary tables are upper case:....libname='TEMP'.... and it will work.</description>
    <pubDate>Fri, 05 Dec 2008 09:31:11 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2008-12-05T09:31:11Z</dc:date>
    <item>
      <title>Deleting SAS Datasets  older than 3 days.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64382#M6494</link>
      <description>Hi,&lt;BR /&gt;
   I am writing a SAS program to delete the datasets older than 3 days&lt;BR /&gt;
&lt;BR /&gt;
In my SAS library, I have files older than 5 days. So whenever I run my program, it has to check the dir to see if there are files older than 3 days. If so, delete the files.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Can somebody provide the SAS code inorder to do the above logic.&lt;BR /&gt;
&lt;BR /&gt;
Thank you.</description>
      <pubDate>Wed, 03 Dec 2008 21:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64382#M6494</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-03T21:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting SAS Datasets  older than 3 days.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64383#M6495</link>
      <description>Hi,&lt;BR /&gt;
I hope the above code helps you.&lt;BR /&gt;
in the example o look for datasets in the libname SASUSER that have been created more than 3 days ago and delete them.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;filename delcode temp;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
 file delcode;&lt;BR /&gt;
 set sashelp.vtable end=eof;&lt;BR /&gt;
 where libname eq 'SASUSER' and memtype eq 'DATA' and datepart(crdate)&amp;lt;(today()-5) ;&lt;BR /&gt;
&lt;BR /&gt;
 if _n_ eq 1 then do;&lt;BR /&gt;
  put 'proc datasets library='  libname ';';&lt;BR /&gt;
  put '	delete ';&lt;BR /&gt;
 end;&lt;BR /&gt;
&lt;BR /&gt;
 put memname;&lt;BR /&gt;
&lt;BR /&gt;
 if eof then do;&lt;BR /&gt;
  put '; run; quit;';&lt;BR /&gt;
 end;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%include delcode;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Cheers,&lt;BR /&gt;
Bruno Silva</description>
      <pubDate>Wed, 03 Dec 2008 22:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64383#M6495</guid>
      <dc:creator>BrunoSilva</dc:creator>
      <dc:date>2008-12-03T22:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting SAS Datasets  older than 3 days.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64384#M6496</link>
      <description>You can try this example:&lt;BR /&gt;
but notice: in filteer (where expresion) you can choose any libarary you wants!!!&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create view temp as&lt;BR /&gt;
select *&lt;BR /&gt;
       ,datepart(crdate) as date&lt;BR /&gt;
from dictionary.tables&lt;BR /&gt;
where libname='WORK'  and calculated date&amp;gt;intnx('day',today(),-3);&lt;BR /&gt;
quit;</description>
      <pubDate>Thu, 04 Dec 2008 10:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64384#M6496</guid>
      <dc:creator>yonib</dc:creator>
      <dc:date>2008-12-04T10:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting SAS Datasets  older than 3 days.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64385#M6497</link>
      <description>just to introduce another idea: &lt;BR /&gt;
Although the datepart() function has achieved what was called for, it isn't really neccessary.&lt;BR /&gt;
But that's OK here, because for such small data volumes, performance is not an issue. &lt;BR /&gt;
However, where data base volumes are significant, for testing a datetime value against a date constant, just extend the constant with 0 time information. Rather than applying a datepart() function on every row, extending the constant happens only once. For example[pre]proc sql ;&lt;BR /&gt;
   create table vtable as select * from sashelp.vtable&lt;BR /&gt;
          where libname = 'WANTED'&lt;BR /&gt;
               &amp;amp; modate lt "%sysfunc( sum( '&amp;amp;sysdate'd, -3), date9):0:0:0"dt&lt;BR /&gt;
               ;&lt;BR /&gt;
quit ;[/pre]&lt;BR /&gt;
&lt;BR /&gt;
PeterC</description>
      <pubDate>Thu, 04 Dec 2008 14:05:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64385#M6497</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2008-12-04T14:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting SAS Datasets  older than 3 days.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64386#M6498</link>
      <description>Thanks for your response.&lt;BR /&gt;
&lt;BR /&gt;
Here is the code I am using as you suggested. But it is giving 0 rows even though the datasets are there in the directory.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql ;&lt;BR /&gt;
select * from sashelp.vtable&lt;BR /&gt;
where libname='temp' &amp;amp; modate lt "%sysfunc( sum( '&amp;amp;sysdate'd, -1), date9):0:0:0"dt;&lt;BR /&gt;
quit &lt;BR /&gt;
&lt;BR /&gt;
Can you please suggest is something wrong in the code.</description>
      <pubDate>Thu, 04 Dec 2008 17:26:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64386#M6498</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-04T17:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting SAS Datasets  older than 3 days.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64387#M6499</link>
      <description>I am using SAS 9. I am not sure whether dictionary.tables &amp;amp;&amp;amp; sashelp.vtable  will work in SAS 9. Because when I hit the below queries, I am getting the 0 rows, even though the library are having files.&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 select memname from dictionary.tables where libname='temp';&lt;BR /&gt;
 quit;&lt;BR /&gt;
 run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 select memname from sashelp.vtable&lt;BR /&gt;
 where libname='temp';&lt;BR /&gt;
 quit;&lt;BR /&gt;
 run;&lt;BR /&gt;
&lt;BR /&gt;
Is there any other option in SAS, where I can find out the 2 days older SAS datasets files and delete it. I was browsing many sites , but nothing worked so far.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Can somebody suggest on this.</description>
      <pubDate>Fri, 05 Dec 2008 04:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64387#M6499</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-05T04:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting SAS Datasets  older than 3 days.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64388#M6500</link>
      <description>The values in the dictionary tables are upper case:....libname='TEMP'.... and it will work.</description>
      <pubDate>Fri, 05 Dec 2008 09:31:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64388#M6500</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-12-05T09:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting SAS Datasets  older than 3 days.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64389#M6501</link>
      <description>Thanks for your response.&lt;BR /&gt;
&lt;BR /&gt;
After making it Uppercase, it is working fine. The query is giving the results based on the criteria.&lt;BR /&gt;
&lt;BR /&gt;
Some times, the SAS library will not be having files to delete. In that case program should exit by giving mesg as no files in the log. &lt;BR /&gt;
But the query I am using is failing.&lt;BR /&gt;
&lt;BR /&gt;
%macro process_start;&lt;BR /&gt;
% global oldfiles;&lt;BR /&gt;
%let oldfiles=;&lt;BR /&gt;
%mend process_start;&lt;BR /&gt;
&lt;BR /&gt;
proc sql NOPRINT;&lt;BR /&gt;
select memname into :oldfiles separated by ' '&lt;BR /&gt;
from dictionary.tables where libname='TEMP' and today() - datepart(modate) &amp;gt; 2;&lt;BR /&gt;
quit;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
if there are no records the oldfiles variable is not getting created. That is the reason the next steps are failing as below:&lt;BR /&gt;
&lt;BR /&gt;
WARNING: Apparent symbolic reference OLDFILES not resolved.&lt;BR /&gt;
ERROR 22-322: Expecting a name&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
can you tell me, if the query is returning zero records in that case how the oldfiles will keep the value 0. So that I can put IF condition.&lt;BR /&gt;
&lt;BR /&gt;
Please suggest.</description>
      <pubDate>Sat, 06 Dec 2008 16:51:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64389#M6501</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-06T16:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting SAS Datasets  older than 3 days.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64390#M6502</link>
      <description>Your %GLOBAL has a blank as in "% GLOBAL".&lt;BR /&gt;
&lt;BR /&gt;
Also consider checking &amp;amp;SQLOBS from the PROC SQL code (inside a macro using %IF), and you should only run your delete code when you have candidates to delete.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sun, 07 Dec 2008 14:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64390#M6502</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-12-07T14:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting SAS Datasets  older than 3 days.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64391#M6503</link>
      <description>Hi FUN&lt;BR /&gt;
&lt;BR /&gt;
Following this thread I suddenly remembered that I have something in my box which needed only a bit of change to cover your requirements.&lt;BR /&gt;
&lt;BR /&gt;
Have a look at the code below.&lt;BR /&gt;
&lt;BR /&gt;
I changed your 'modate' part in the clause to 'coalesce(modate,crdate)' as I saw in the dictionary table that there are entries with a blank modate.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
%macro CleanUpLib(CleanupLib=);&lt;BR /&gt;
  options mprint;&lt;BR /&gt;
  %local dropmems;&lt;BR /&gt;
 &lt;BR /&gt;
  proc sql noprint nowarn; &lt;BR /&gt;
    select catx('.',libname,memname) into :dropmems separated by ',' &lt;BR /&gt;
      from dictionary.tables &lt;BR /&gt;
      where libname =%upcase("&amp;amp;CleanupLib") and memtype="DATA" &lt;BR /&gt;
            and today()-datepart(coalesce(modate,crdate)) &amp;gt; 2;&lt;BR /&gt;
    %if &amp;amp;dropmems ne %then %do;&lt;BR /&gt;
      %put ************ Tables will be dropped ******;&lt;BR /&gt;
      %put Dropmems=&amp;amp;dropmems;&lt;BR /&gt;
      drop table &amp;amp;dropmems;&lt;BR /&gt;
    %end;&lt;BR /&gt;
    %else %do; &lt;BR /&gt;
      %put ************ No tables to be dropped ******;&lt;BR /&gt;
    %end;&lt;BR /&gt;
  quit; &lt;BR /&gt;
  run; &lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%CleanUpLib(CleanupLib=MyLib)

Message was edited by: Patrick</description>
      <pubDate>Tue, 09 Dec 2008 05:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Deleting-SAS-Datasets-older-than-3-days/m-p/64391#M6503</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-12-09T05:20:55Z</dc:date>
    </item>
  </channel>
</rss>

