BookmarkSubscribeRSS Feed
DG19841
Calcite | Level 5

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. 

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ballardw
Super User

@RW9

I think you meant:

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

Patrick
Opal | Level 21

@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/ 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1996 views
  • 2 likes
  • 4 in conversation