<?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: Removing tables/data-sets based on a condition? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-tables-data-sets-based-on-a-condition/m-p/179750#M302840</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi RW,&lt;/P&gt;&lt;P&gt;First of all, Thank you so much for your super quick response and help. I think I made a silly mistake in my question and I am sincerely sorry for that. Forgive me!.Basically, just like your example i have N number of datasets in a folder. As part of data retention exercise, I just want to only retain 3 or 4 days data from a given a date.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, for today, today- 3 days data is what i want to keep. And, for tomorrow, tomorrow-3 days data, and for the day after, day after tomorrow-3days data and it goes on incremental.&lt;/P&gt;&lt;P&gt;I have a feeling that I have explained better this time as I personally have understood the requirement better myself&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry and Thanks for the patience,&lt;/P&gt;&lt;P&gt;Charlotte&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Jan 2015 10:50:16 GMT</pubDate>
    <dc:creator>CharlotteCain</dc:creator>
    <dc:date>2015-01-13T10:50:16Z</dc:date>
    <item>
      <title>Removing tables/data-sets based on a condition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-tables-data-sets-based-on-a-condition/m-p/179747#M302837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I have a need to clear or in other words delete tables from a library based on a condition. The condition is that some/all of the data-sets needs to be deleted from a library over a period&amp;nbsp; of PREVIOUS 5 days from a given date..&lt;/P&gt;&lt;P&gt;Let's say i have a library named eg with datasets data1-data50. I want to delete all of it in certain cases and keep some of it in other cases.&lt;/P&gt;&lt;P&gt;Scenario1:&lt;/P&gt;&lt;P&gt;To make it more precise for understanding, if the date is 12/25/2014, I'd need to delete 25th, 24th, 23rd,22nd and the 21st datasets(that is minus 5 days from 25th)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scenario2:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To keep the 25th datasets and delete only the previous 4 days 24th, 23rd,22nd and the 21st datasets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like it dynamic as there is a certain possibility of changing the condition in future, which is the number of days to delete currently being 5 to 3 or 8 or whatever number.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;Charlotte&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 09:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-tables-data-sets-based-on-a-condition/m-p/179747#M302837</guid>
      <dc:creator>CharlotteCain</dc:creator>
      <dc:date>2015-01-13T09:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Removing tables/data-sets based on a condition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-tables-data-sets-based-on-a-condition/m-p/179748#M302838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well, below is working code which does what you ask.&amp;nbsp; However I really wouldn't recommend you do this.&amp;nbsp; Why would you want to have a table for each date?&amp;nbsp; You lose a lot of functionality within SAS processing (by group processing), and you create complications for yourself.&amp;nbsp; I would suggest creating a base table, with a column for date.&amp;nbsp; Into this table one each day you append your data setting date to the date for that bit of data.&amp;nbsp; You can then do by group processing on it, easily remove data if you want with an if statement in a datastep, keep audit trail on it etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let start_date='01jan2015'd;&lt;BR /&gt;%let to_date='03jan2015'd;&lt;/P&gt;&lt;P&gt;data have1 have2 have3 have4 have5;&lt;BR /&gt;&amp;nbsp; set sashelp.class;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data tmp;&lt;BR /&gt;&amp;nbsp; set sashelp.vtable (where=(libname="WORK" and substr(memname,1,4)="HAVE"));&lt;BR /&gt;&amp;nbsp; remove_to=&amp;amp;to_date.-&amp;amp;start_date.;&lt;BR /&gt;&amp;nbsp; if input(substr(memname,5),best.) &amp;gt;= remove_to then call execute('proc datasets library=work nolist nowarn; delete '||strip(memname)||'; quit;');&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 10:00:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-tables-data-sets-based-on-a-condition/m-p/179748#M302838</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-01-13T10:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: Removing tables/data-sets based on a condition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-tables-data-sets-based-on-a-condition/m-p/179749#M302839</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This macro is a starting point. there are some notes in the log about the invalid argument of the INPUT function, but there will cause no harm.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*prepare some data*/&lt;/P&gt;&lt;P&gt;data a_20131212 a_20131213 a_20131214 a_20140112;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;run; &lt;/P&gt;&lt;P&gt;%macro delt(lib, inpdate, daysbehinddel);&lt;/P&gt;&lt;P&gt;%let refdate=%sysfunc(intnx(day,&amp;amp;inpdate, %eval((-1)*&amp;amp;daysbehinddel)));&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select memname into :deltables separated by " " from dictionary.tables&lt;BR /&gt;where not(missing(input(scan(memname,2,"_"),yymmdd8.))) &lt;BR /&gt;and&amp;nbsp; input(scan(memname,2,"_"),yymmdd8.) lt %eval(&amp;amp;refdate) and&lt;BR /&gt;upcase(libname)=upcase("&amp;amp;lib");&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;deltables;&lt;/P&gt;&lt;P&gt;proc datasets library=&amp;amp;lib nolist;&lt;BR /&gt;delete &amp;amp;deltables;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%mend delt;&lt;/P&gt;&lt;P&gt;/*example of calling the macro*/&lt;/P&gt;&lt;P&gt;%delt(work,"01JAN2014"d,5)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 10:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-tables-data-sets-based-on-a-condition/m-p/179749#M302839</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2015-01-13T10:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Removing tables/data-sets based on a condition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-tables-data-sets-based-on-a-condition/m-p/179750#M302840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi RW,&lt;/P&gt;&lt;P&gt;First of all, Thank you so much for your super quick response and help. I think I made a silly mistake in my question and I am sincerely sorry for that. Forgive me!.Basically, just like your example i have N number of datasets in a folder. As part of data retention exercise, I just want to only retain 3 or 4 days data from a given a date.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, for today, today- 3 days data is what i want to keep. And, for tomorrow, tomorrow-3 days data, and for the day after, day after tomorrow-3days data and it goes on incremental.&lt;/P&gt;&lt;P&gt;I have a feeling that I have explained better this time as I personally have understood the requirement better myself&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry and Thanks for the patience,&lt;/P&gt;&lt;P&gt;Charlotte&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 10:50:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-tables-data-sets-based-on-a-condition/m-p/179750#M302840</guid>
      <dc:creator>CharlotteCain</dc:creator>
      <dc:date>2015-01-13T10:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Removing tables/data-sets based on a condition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-tables-data-sets-based-on-a-condition/m-p/179751#M302841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No need to remove then, just do:&lt;/P&gt;&lt;P&gt;have1, have2, have3&amp;nbsp; This is what we have day1.&lt;/P&gt;&lt;P&gt;New data received:&lt;/P&gt;&lt;P&gt;data have1; set have2; run;&lt;/P&gt;&lt;P&gt;data have2; set have3; run;&lt;/P&gt;&lt;P&gt;data have2; set new_date; run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;That way you only keep the latest 3.&amp;nbsp; However I would still advise not going down this route.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 11:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-tables-data-sets-based-on-a-condition/m-p/179751#M302841</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-01-13T11:05:18Z</dc:date>
    </item>
  </channel>
</rss>

