<?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 data from a daily created dataset based on Date Range in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-from-a-daily-created-dataset-based-on-Date-Range/m-p/708299#M217659</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I need your assistance . I am writing data daily into a dataset and distinguishing this with a Date_Field.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not want not mare than 10 days data in this dataset. i.e as part of housekeeping I want to delete data older than 10 days from this dataset .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample code:&lt;/P&gt;
&lt;PRE&gt;data a;
	format x date9.;
	x=today();

	do i=1 to 15;
		x+1;
		output;
	end;
run;
&lt;BR /&gt;Output:&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dennis_oz_0-1609021250854.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53034i5E8FCC73004CB4C8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dennis_oz_0-1609021250854.png" alt="dennis_oz_0-1609021250854.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the above case I would like to delete data that is starting from 28- Dec till 01-Jan-2021.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;D&lt;/P&gt;</description>
    <pubDate>Sat, 26 Dec 2020 22:22:53 GMT</pubDate>
    <dc:creator>dennis_oz</dc:creator>
    <dc:date>2020-12-26T22:22:53Z</dc:date>
    <item>
      <title>Delete data from a daily created dataset based on Date Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-from-a-daily-created-dataset-based-on-Date-Range/m-p/708299#M217659</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I need your assistance . I am writing data daily into a dataset and distinguishing this with a Date_Field.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not want not mare than 10 days data in this dataset. i.e as part of housekeeping I want to delete data older than 10 days from this dataset .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample code:&lt;/P&gt;
&lt;PRE&gt;data a;
	format x date9.;
	x=today();

	do i=1 to 15;
		x+1;
		output;
	end;
run;
&lt;BR /&gt;Output:&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dennis_oz_0-1609021250854.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53034i5E8FCC73004CB4C8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dennis_oz_0-1609021250854.png" alt="dennis_oz_0-1609021250854.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the above case I would like to delete data that is starting from 28- Dec till 01-Jan-2021.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;D&lt;/P&gt;</description>
      <pubDate>Sat, 26 Dec 2020 22:22:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-data-from-a-daily-created-dataset-based-on-Date-Range/m-p/708299#M217659</guid>
      <dc:creator>dennis_oz</dc:creator>
      <dc:date>2020-12-26T22:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: Delete data from a daily created dataset based on Date Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-from-a-daily-created-dataset-based-on-Date-Range/m-p/708307#M217662</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
	format x date9.;
	x=today();
	do i=1 to 15;
		x+1;
		if not ('28DEC2020'd&amp;lt;=x&amp;lt;='01JAN2021'd) then output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you just want 10 observations, then when you go to use data set A, you can use something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=a(obs=10);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Dec 2020 23:26:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-data-from-a-daily-created-dataset-based-on-Date-Range/m-p/708307#M217662</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-12-26T23:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Delete data from a daily created dataset based on Date Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-from-a-daily-created-dataset-based-on-Date-Range/m-p/708310#M217665</link>
      <description>&lt;P&gt;If you want just the top 10 dates regardless of the period chosen:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  format MyDate date9.; 
  do MyDate = '28Dec2020'd to '11Jan2021'd;
    output;
  end;
run;

proc rank data = have out = want1 descending;
  ranks MyDateRank;
  var MyDate;
run;

data want2;
  set want1;
  where MyDateRank &amp;lt;= 10;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Dec 2020 23:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-data-from-a-daily-created-dataset-based-on-Date-Range/m-p/708310#M217665</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-12-26T23:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Delete data from a daily created dataset based on Date Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-from-a-daily-created-dataset-based-on-Date-Range/m-p/708311#M217666</link>
      <description>&lt;P&gt;Using the same data set name for a data set that not only gets new data, but also has old data removed, is dangerous when done in a normal data step - because the removal is likely irreversible.&amp;nbsp; One mistake and erroneously removed data is irretrievable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One possibility to avoid this risk is to just append new data, and remove none.&amp;nbsp; Then introduce a filter for data-access purposes to access only the last ten days.&amp;nbsp; Let's assume there is dataset file HAVE with data that goes back any number of days, with daily data appended, but no data removed.&amp;nbsp; You could then permanently define a "dataset view" of that dataset file, that will always retrieve only data within the last ten calendar days.&amp;nbsp; The dataset view does not have to be redefined daily - once is enough.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vhave / view=vhave;
  set have;
  where x-9 &amp;gt;= "&amp;amp;sysdate9"d;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could then do all your subsequent reporting/analysis tasks using VHAVE, no matter how many updates have been applied to HAVE.&amp;nbsp; That's because the dataset view is nothing more than a pre-defined process.&amp;nbsp; It doesn't write data to disk, but it looks&amp;nbsp; like a normal dataset file to any subsequent procedure that accesses it.&amp;nbsp; That is, you could do something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=vhave;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, &amp;amp;SYSDATE9 is an automatic macrovar.&amp;nbsp; To see what it looks like issue the macro statement %PUT &amp;amp;=SYSDATE9.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, with daily updates, the original dataset HAVE would probably need to be pruned from time-to-time.&amp;nbsp; But that could be done in a controlled process that included backup or snapshot files to protect against inadvertent data destruction.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Dec 2020 23:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-data-from-a-daily-created-dataset-based-on-Date-Range/m-p/708311#M217666</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-12-26T23:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Delete data from a daily created dataset based on Date Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-from-a-daily-created-dataset-based-on-Date-Range/m-p/708325#M217673</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
	format x date9.;
	x=today();

	do i=1 to 15;
		x+1;
		output;
	end;
run;

%macro delete_(indata=,startdate=,enddate=);
proc sql;
delete from &amp;amp;indata where x between &amp;amp;startdate. and &amp;amp;enddate.;
quit;
%mend;
%delete_(indata=a,startdate='28DEC2020'D,enddate='01JAN2021'd);

proc print data=a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 27 Dec 2020 07:21:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-data-from-a-daily-created-dataset-based-on-Date-Range/m-p/708325#M217673</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2020-12-27T07:21:29Z</dc:date>
    </item>
  </channel>
</rss>

