Merging Datasets
Posted: 21 July 2014 10:18 PM   [ Ignore ]
Total Posts:  6
Joined  2014-06-16

I have two datasets both from the same database.

One dataset hasn’t been edited but one dataset has had observations removed.
Therefore, one dataset has observations that the other doesn’t have.

I want to merge the two datasets but now the company codes (gvkey) and financial year (fyear) variables do not match.

The larger dataset has two variables (accounts receiveable and accounts payable) that I want to move onto the other edited dataset (I didn’t think I’d need them but I do now). I want them to move over when the gvkey and fyear match.

I hope that makes sense.

Any help would be appreciated

Posted: 22 July 2014 08:08 AM   [ Ignore ]   [ # 1 ]
Total Posts:  901
Joined  2011-09-19


Something like this?

proc sql;
create table combined as select a.*, b.arb.ap
  from edited a
original b
  where a
.gvkey b.gvkey and a.fyear b.fyear;

If you were to use Excel, you could make a ‘key’ variable with concatenate: key = concatenate (a1, “_”, b1)  where a1 would be the cell with gvkey, and b1 the fyear.
Then you can use ‘VLOOKUP’ (Google ‘Excel vlookup examples’ for examples) to select variables from another worksheet (holding ar, ap), into a worksheet where they are needed.

best regards,



To reply/post new questions: Please use the group WRDS/SAS on Google Groups!