DATA Step, Macro, Functions and more

How to maintain a rolling 30 day data set

Reply
New User
Posts: 1

How to maintain a rolling 30 day data set

[ Edited ]

I currently have a dataset that has 2 years worth of data.  I would like to reduce this to a rolling 30 days,  every day I would remove 1 day and store else where and add another day. 

I need to do this so processing time is reduced and to save space.  I will be zipping the data that is removed and storing on a separate server. Current size of the table with 2 years data is 29GB and each day I am adding  200k lines of data with 100 columns.  I would like to know the quickest way to remove the oldest date and insert the data so I only have 30 days worth of data in the table. 

Super User
Super User
Posts: 9,813

Re: How to maintain a rolling 30 day data set

Well, I am going to assume that each day's data that you "zip and remove" will not need to be appended to older zipped data (i.e. there would not be one big old data file which gets zipped, but one for each day?) - if thats not the case then its not a good idea to zip as, each time you would need to extract, append, re-zip, which is far more work.  

As for the day, that is simple - you haven't given any test data, so I am just going to provide some generic code which you will need to fit to your data:

data want archive;
  set alldata;
  if date < today() - 30 then output archive;
  else output;
want;

This assumes there is a date variable in your data.  Archive can then be zipped off and moved somewhere else, this will keep want as only the last 30 days of data.

Super User
Posts: 13,898

Re: How to maintain a rolling 30 day data set

@RW9

I think you meant:

data want archive;
  set alldata;
  if date < today() - 30 then output archive;
  else output want;
run;

Respected Advisor
Posts: 4,779

Re: How to maintain a rolling 30 day data set

@DG19841

I'm normally creating daily SAS tables for such use cases <table name>_<yyyymmdd> and then create views over the tables. With such an approach you simply create the newest dates table and then recreate the view over the time period you need (i.e. one for current date, one for current month etc. - SQL UNION ALL CORR).

 

You then simply archive SAS tables older than your threshold. I would create a zip file per table but you can also add a table to an existing zip archive without the need to "re-zip" everything.

https://blogs.sas.com/content/sasdummy/2016/03/04/add-files-to-a-zip-archive-with-filename-zip/ 

Ask a Question
Discussion stats
  • 3 replies
  • 185 views
  • 2 likes
  • 4 in conversation