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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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