02-16-2018 06:26 AM - edited 02-16-2018 06:40 AM
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.
02-16-2018 07:02 AM
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.
02-16-2018 06:38 PM
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.