BookmarkSubscribeRSS Feed
Amir8766
Calcite | Level 5

Dear all, 

 

I am using sas 9.4 and trying to merge a M&A dataset (DATASET B) with a 60,000 observation with a compustat dataset (DATASET A) with over 800,000 observation. The B dataset has 2 unique identifiers. for the US firm it has CUSIP and for non-us firm it has sedol,  and year that I can use for merge. on the other hand, the A dataset has both the identifiers and the year. I was wondering if there is any way that I can merge the two datasets (in a way that dataset A is a left join that keeps all the variables) based on identifier 1 OR identifier 2. meaning use identifier 1 for merge if the B has identifier 1 OR use identifier 2 if the B has identifier 1.

 This is what I originally used and It absolutely did not work since half of the data has cusip and the other has sedol. Perhaps the data step be a better choice for these type of merging.

proc sql;

create table mna5 as select unique *

from comp as a left join mna as b

on a.cusip=b.cusip and a.sedol=b.sedol and a.year=b.year;

quit;

 

Thanks

2 REPLIES 2
ballardw
Super User

A couple of short examples of the data that demonstrate the problem would be helpful. A data step to create an example using the variables of interest and the cases that you have and the final desired result would be optimal.

 

I would be tempted to create a set for matches on cuspid, another from matches on sedol, combine the results and remove duplicates as a crude easy to understand approach.

Then look for the ones that had no matches.

 

 

Astounding
PROC Star

Would this work?

 

on (a.cusip=b.cusip or a.sedol=b.sedol) and a.year=b.year;

 

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
  • 2 replies
  • 905 views
  • 0 likes
  • 3 in conversation