Help using Base SAS procedures

how to update a master dataset

Reply
Occasional Contributor
Posts: 8

how to update a master dataset

Hi,

I'm wondering what is the best way to update a master dataset from several transactional dataset.

The situation is , master contains 1728 records, and i have 10 different transactional dataset to update this master dataset ( one for each month), the goal is to see after 10 months, how these 1728 records would look like. so if the transac data contains more records than master, don't add them. if contains less records and non-matching records, only update the matching ones and leave the unmatched stay the same. I've tried update statement together with merge statement, part of my code is as follows:

data tmp#

  update result_start

            result#

  by ERFAC:

  run;

data new#

    merge result_start(in=a)

             tmp&num(in=b);

   by ERFAC;

   if a and b ;

run;

so here result_start is my master data, for each iteration, i want to use result&num to update result_start, however, the update statement would add new records onto master data, so i have to do a merge step to get rid of the unwanted records and hopefully keep the master data updated.

Could anyone tell me if i was doing anything wrong here ,and if there is a better way to do this.

Thanks!

Super User
Posts: 5,518

Re: how to update a master dataset

Untested, but I imagine you could do this in one step and eliminate the MERGE:

data tmp#

  update result_start (in=in_master)

            result#

  by ERFAC:

  if in_master=0 then delete;

  run;

Super User
Super User
Posts: 7,083

Re: how to update a master dataset

You do know how the UPDATE statement works right?  How it handles missing values and repeats of BY variables is very different than the MERGE statement.

The UPDATE statement is for applying transactions.  It requires exactly two datasets.  But you could make a view that combines all of your transactions into one and then apply them.

data transactions/ view=transactions  ;

  set result1 - result10 ;

  by id;

run;

data want ;

  update master transactions;

  by id;

run;

Ask a Question
Discussion stats
  • 2 replies
  • 206 views
  • 0 likes
  • 3 in conversation