Return to Homepage

Goto the Tip of the Month Archive

Other interesting pages ...
LinkedIn Profile
SAS Cheat Sheet
Useful SAS Code
Full SAS Example
Basic Statistics
Contact Information

SAS Tip of the Month
January 2013
(for SAS and WPS)

There are a number of ways which a master dataset can be updated from a transaction dataset, but here is an olde and a goodie which I still use occasionally.

Here is some data in my MASTER dataset:

   Stadium      Unsold_Seats  Last_Update
   North Side      20,000      31DEC2012
   South Side      18,000      31DEC2012
   East Side       21,000      31DEC2012
   West Side       16,000      31DEC2012
   Central         14,000      31DEC2012

For our example, on January 1st East Side and Central locations were open and at the end of the day the tickets unsold were:

   Stadium      Unsold_Seats
   East Side       19,000
   Central         11,000

Now lets update using the following code:

   proc sort data=MASTER;
      by stadium last_update;
      set TRANSACTION;
   proc sort data=TRANSACTION;
      by stadium last_update;
   data MASTER;
      by stadium last_update;
      if last.stadium;

In the TRANSACTION dataset we have put the date of the transaction in the file, then sorted both datasets, then merged by the STADIUM and LAST_UPDATE variables, taking the last STADIUM value into the MASTER dataset.

There are a number of variations of this that can be useful, but this is the basic update.

Have a safe and happy January.

Updated January 01, 2013