<?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 Delete SAS Dataset 3 days prior to today in work library in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-SAS-Dataset-3-days-prior-to-today-in-work-library/m-p/460141#M284629</link>
    <description>&lt;P&gt;Everyday a job runs and it creates a dataset with date extension in the library called final. For example date extension for the first record read this 2018 is the year, 05 is the month and 04 is the day which is yymmddn8.&amp;nbsp; date format&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample_20180504&lt;/P&gt;&lt;P&gt;Sample_20180503&lt;/P&gt;&lt;P&gt;Sample_20180502&lt;/P&gt;&lt;P&gt;Sample_20180501&lt;/P&gt;&lt;P&gt;Sample_20180430&lt;/P&gt;&lt;P&gt;Sample_20180429&lt;/P&gt;&lt;P&gt;Sample_20180428&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a macro or code which will delete the tables or dataset in the final library which has file extension more than 3 days old. In the above example all the dataset older than 2nd May 2018 extension should be deleted if I run it today which is 4th May 2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the code but it did not work out&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; call symput('to_delete',catt('sample_',year(today())-0,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; put(intnx('day',today(),-3), z2.)));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Similarly you can put for month but it only deletes one record which is less than 3 that is Sample_20180501. I want to delete all that are older than 3 days old which is till 28th april 2018 record&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>Fri, 04 May 2018 19:09:57 GMT</pubDate>
    <dc:creator>sameer112217</dc:creator>
    <dc:date>2018-05-04T19:09:57Z</dc:date>
    <item>
      <title>Delete SAS Dataset 3 days prior to today in work library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-SAS-Dataset-3-days-prior-to-today-in-work-library/m-p/460141#M284629</link>
      <description>&lt;P&gt;Everyday a job runs and it creates a dataset with date extension in the library called final. For example date extension for the first record read this 2018 is the year, 05 is the month and 04 is the day which is yymmddn8.&amp;nbsp; date format&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample_20180504&lt;/P&gt;&lt;P&gt;Sample_20180503&lt;/P&gt;&lt;P&gt;Sample_20180502&lt;/P&gt;&lt;P&gt;Sample_20180501&lt;/P&gt;&lt;P&gt;Sample_20180430&lt;/P&gt;&lt;P&gt;Sample_20180429&lt;/P&gt;&lt;P&gt;Sample_20180428&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a macro or code which will delete the tables or dataset in the final library which has file extension more than 3 days old. In the above example all the dataset older than 2nd May 2018 extension should be deleted if I run it today which is 4th May 2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the code but it did not work out&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; call symput('to_delete',catt('sample_',year(today())-0,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; put(intnx('day',today(),-3), z2.)));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Similarly you can put for month but it only deletes one record which is less than 3 that is Sample_20180501. I want to delete all that are older than 3 days old which is till 28th april 2018 record&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>Fri, 04 May 2018 19:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-SAS-Dataset-3-days-prior-to-today-in-work-library/m-p/460141#M284629</guid>
      <dc:creator>sameer112217</dc:creator>
      <dc:date>2018-05-04T19:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Delete SAS Dataset 3 days prior to today in work library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-SAS-Dataset-3-days-prior-to-today-in-work-library/m-p/460145#M284630</link>
      <description>&lt;P&gt;No need for macro, generate proc datasets statements using Call execute reading from sashelp,vtable&amp;nbsp;&lt;/P&gt;&lt;P&gt;--&amp;gt;&lt;BR /&gt;if today()-3&amp;lt;=crdate&amp;lt;today() then call execute&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 sashelp.vtable end=last;
if _n_=1 then call execute ('proc datasets lib=work;');
if  today()-3&amp;lt;=datepart(crdate)&amp;lt;today()  then call execute ("delete "||' '||memname||";");
if last then call execute('quit;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 May 2018 20:09:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-SAS-Dataset-3-days-prior-to-today-in-work-library/m-p/460145#M284630</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-04T20:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Delete SAS Dataset 3 days prior to today in work library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-SAS-Dataset-3-days-prior-to-today-in-work-library/m-p/460226#M284631</link>
      <description>Novinosrin, it will delete dataset which is 3 days older however my job is creating a dataset with an extension&lt;BR /&gt;&lt;BR /&gt;Sample_20180504 . It is 04th may, 2018.The date part is an extension that needs attention for a particular dataset name and not creation date for every dataset</description>
      <pubDate>Sat, 05 May 2018 02:56:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-SAS-Dataset-3-days-prior-to-today-in-work-library/m-p/460226#M284631</guid>
      <dc:creator>sameer112217</dc:creator>
      <dc:date>2018-05-05T02:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: Delete SAS Dataset 3 days prior to today in work library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-SAS-Dataset-3-days-prior-to-today-in-work-library/m-p/460246#M284632</link>
      <description>&lt;P&gt;I think that the following will do what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sashelp.vtable (where=(libname eq 'WORK'));
  if _n_=1 then pattern_num = PRXPARSE("/_\d{8}$/");
  retain pattern_num;
  position=PRXMATCH(pattern_num,trim(memname));
  if position then do;
    if input(substr(memname,position+1),yymmdd8.) le today()-3 then do;
      forexec=catt('proc delete data=work.',memname,';run;');
      call execute(forexec);
    end;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 May 2018 14:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-SAS-Dataset-3-days-prior-to-today-in-work-library/m-p/460246#M284632</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-05-05T14:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: Delete SAS Dataset 3 days prior to today in work library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-SAS-Dataset-3-days-prior-to-today-in-work-library/m-p/460273#M284633</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89720"&gt;@sameer112217&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Here another&amp;nbsp;coding option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*** create sample data ***/
libname final (work);
data _null_;
  dcl hash h1(dataset:'sashelp.class');
  h1.defineKey('name');
  h1.defineData(all:'y');
  h1.defineDone();
  set sashelp.class(obs=1);
  do date=today()-5 to today();
    h1.output(dataset:cats('final.sample_',put(date,yymmddn8.)));
  end;
run;

/*** delete ds with a date parte older today()-3 ***/
/* create list of ds to be deleted */
%let del_list=;
proc sql noprint;
  select memname into :del_list separated by ' '
  from dictionary.tables
  where libname='FINAL' and memname like 'SAMPLE^_%' escape '^'
    and input(scan(memname,-1,'_'),yymmdd8.)&amp;lt;today()-3
  ;
quit;

/* delete ds in list. */
/* use additional dummy ds name to avoid errors in case &amp;amp;del_list is empty */
proc datasets lib=final nolist nowarn;
  delete &amp;amp;del_list _dummy_123456789;
  run;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 May 2018 02:08:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-SAS-Dataset-3-days-prior-to-today-in-work-library/m-p/460273#M284633</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-05-06T02:08:41Z</dc:date>
    </item>
  </channel>
</rss>

