BookmarkSubscribeRSS Feed
sriharivn
Fluorite | Level 6

Thanks Kurt. One clarification on the last step.


I want to keep all the old records for the customer (flag='N') and delete only the Ys in the history for the customers in X. I want to keep the Ys for the other records which are not present in X.

 

data customer_history_new;
set customer_history;
if current ne 'Y' or put(customer_no,$checkfmt.) = 'no';
run;

 

I guess this will remove all the Ys in the history and give me only Ns and also remove the X customers.

Is my understanding right?

ChrisNZ
Tourmaline | Level 20

1- Formats can be slow for large numbers of values in my experience.

 

2- Keep in mind that a sorted table will be fast not only for maintenance for you as an admin, but also for all users.

 

3- Rewriting sorted tables is just a matter of copying the table, so if you have the space it should not take long considering the volume you have.

 

4- If you are I/O bound, using SPDE with binary compression instead of the V9 engine is a must as it will typically decreases table size by 90%. This engine also processes indexes much faster.

 

5- When doing such updates, I like to keep tabs of what happens in the log and usually use something like:

data NEWHISTORY (drop=_:); 
  if LASTOBS then put _REPLACED= _ADDED= _KEPT=; 
  merge HISTORY (in=OLD)
        NEW     (in=NEW)
        end=LASTOBS;
  by CUSTOMERNO CURRENT_FLAG;
  if OLD and NEW then _REPLACED+1;
  else if OLD then    _KEPT    +1;
  else                _ADDED   +1;
run;

proc sort data=NEWHISTORY 
          out =HISTORY(index=( ... )) 
          presorted;
  by CUSTOMERNO CURRENT_FLAG ;
run;

Add the deletion logic as you see fit for your data (like:  if DEL then do; _DELETE+1; delete; end; )

 

The sort step is there just because SAS have been sitting on their hands and there is still no way to set the SORT VALIDATED flag in the data step. PROC SORT just copies the table here.

 

Index creation is fast on sorted tables.

 

 

 

 

 

 

 

 

 

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 17 replies
  • 3441 views
  • 5 likes
  • 6 in conversation